<commit_before><?php

namespace Oro\Bundle\EntityExtendBundle\Form\Type;

use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
 * An enum value selector based on 'select2' form type
 */
class EnumSelectType extends AbstractEnumType
{
    /**
     * {@inheritdoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        parent::buildView($view, $form, $options);

        $this->disableChoices($view, $options['disabled_values']);
        $this->excludeChoices($view, $options['excluded_values']);
    }

    /**
     * {@inheritdoc}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        parent::setDefaultOptions($resolver);

        $defaultConfigs = [
            'allowClear'  => true,
            'placeholder' => 'oro.form.choose_value'
        ];

        $resolver->setDefaults(
            [
                'empty_value' => null,
                'empty_data'  => null,
                'configs'     => $defaultConfigs,
                'disabled_values' => [],
                'excluded_values' => [],
            ]
        );
        $resolver->setAllowedTypes([
            'disabled_values' => ['array', 'callable'],
            'excluded_values' => ['array', 'callable'],
        ]);
        $resolver->setNormalizers(
            [
                'empty_value' => function (Options $options, $value) {
                    return !$options['expanded'] && !$options['multiple']
                        ? ''
                        : $value;
                },
                // this normalizer allows to add/override config options outside
                'configs' => function (Options $options, $value) use (&$defaultConfigs) {
                    return array_merge($defaultConfigs, $value);
                }
            ]
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getParent()
    {
        return 'genemu_jqueryselect2_translatable_entity';
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return $this->getBlockPrefix();
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'oro_enum_select';
    }

    /**
     * @param FormView       $view
     * @param array|callable $disabledChoices
     */
    protected function disableChoices(FormView $view, $disabledChoices)
    {
        if (empty($disabledChoices)) {
            return;
        }
<commit_msg>BB-6346: Show block with variant fields at product view page on frontend  - fixes after merge<commit_after><?php

namespace Oro\Bundle\EntityExtendBundle\Form\Type;

use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
 * An enum value selector based on 'select2' form type
 */
class EnumSelectType extends AbstractEnumType
{
    const NAME = 'oro_enum_select';

    /**
     * {@inheritdoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        parent::buildView($view, $form, $options);

        $this->disableChoices($view, $options['disabled_values']);
        $this->excludeChoices($view, $options['excluded_values']);
    }

    /**
     * {@inheritdoc}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        parent::setDefaultOptions($resolver);

        $defaultConfigs = [
            'allowClear'  => true,
            'placeholder' => 'oro.form.choose_value'
        ];

        $resolver->setDefaults(
            [
                'empty_value' => null,
                'empty_data'  => null,
                'configs'     => $defaultConfigs,
                'disabled_values' => [],
                'excluded_values' => [],
            ]
        );
        $resolver->setAllowedTypes([
            'disabled_values' => ['array', 'callable'],
            'excluded_values' => ['array', 'callable'],
        ]);
        $resolver->setNormalizers(
            [
                'empty_value' => function (Options $options, $value) {
                    return !$options['expanded'] && !$options['multiple']
                        ? ''
                        : $value;
                },
                // this normalizer allows to add/override config options outside
                'configs' => function (Options $options, $value) use (&$defaultConfigs) {
                    return array_merge($defaultConfigs, $value);
                }
            ]
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getParent()
    {
        return 'genemu_jqueryselect2_translatable_entity';
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return $this->getBlockPrefix();
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return self::NAME;
    }

    /**
     * @param FormView       $view
     * @param array|callable $disabledChoices
     */
    protected function disableChoices(FormView $view, $disabledChoices)
    {
        if (empty($disabledChoices)) {
            return;
        }

{'fraction_non_alphanumeric': 0.12687112084702445, 'fraction_numerical': 0.0014603870025556773, 'mean_word_length': 1.9425349087003223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1217239', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1476, 'n_words': 275}