<commit_before><?php

/**
 * LICENSE: This file is subject to the terms and conditions defined in
 * file 'LICENSE', which is part of this source code package.
 *
 * @copyright 2016 Copyright(c) - All rights reserved.
 */

namespace Rafrsr\FormExtraBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
 * Class ToggleFormTypeExtension
 */
class ToggleFormTypeExtension extends AbstractTypeExtension
{
    /**
     * @inheritdoc
     */
    public function finishView(FormView $view, FormInterface $form, array $options)
    {
        //TODO: support for expanded choices (radio buttons)

        if (isset($options['toggle_group'])) {
            $groups = (array)$options['toggle_group'];

            if ($groups) {
                $view->vars['toggle_groups'] = $groups;
            }
        }

        if (isset($options['toggle'])
            || isset($options['toggle_prefix'])
        ) {
            $view->vars['toggle'] = true;

            //convert into class name
            if ($options['toggle']) {
                $view->vars['attr']['data-toggle'] = '.toggle_group_' . $options['toggle'];
                $view->vars['attr']['data-reverse-toggle'] = '.toggle_group_not_' . $options['toggle'];
            }

            if ($options['toggle_prefix']) {
                $view->vars['attr']['data-toggle-prefix'] = '.toggle_group_' . $options['toggle_prefix'];
                $view->vars['attr']['data-toggle-reverse-prefix'] = '.toggle_group_not_' . $options['toggle_prefix'];
            }
        }
    }

    /**
     * @inheritdoc
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'toggle' => null,
                'toggle_prefix' => null,
                'toggle_group' => null,
            ]
        );

        $resolver->setAllowedTypes('toggle', ['null', 'string']);
        $resolver->setAllowedTypes('toggle_prefix', ['null', 'string']);
        $resolver->setAllowedTypes('toggle_group', ['null', 'string', 'array']);
    }

    /**
     * @inheritdoc
     */
    public function getExtendedType()
    {
        return FormType::class;
    }
}<commit_msg>[FormToggle] Fix support to reversed<commit_after><?php

/**
 * LICENSE: This file is subject to the terms and conditions defined in
 * file 'LICENSE', which is part of this source code package.
 *
 * @copyright 2016 Copyright(c) - All rights reserved.
 */

namespace Rafrsr\FormExtraBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ToggleFormTypeExtension extends AbstractTypeExtension
{
    /**
     * {@inheritdoc}
     */
    public function finishView(FormView $view, FormInterface $form, array $options)
    {
        //TODO: support for expanded choices (radio buttons)

        if (isset($options['toggle_group'])) {
            $groups = (array) $options['toggle_group'];

            if ($groups) {
                $view->vars['toggle_groups'] = $groups;
            }
        }

        if (isset($options['toggle'])
            || isset($options['toggle_prefix'])
        ) {
            $view->vars['attr']['form-toggle'] = null;

            //convert into class name
            if ($options['toggle']) {
                $view->vars['attr']['data-toggle'] = '.toggle_group_'.$options['toggle'];
                $view->vars['attr']['data-reverse-toggle'] = '.toggle_group_not_'.$options['toggle'];
            }

            if ($options['toggle_prefix']) {
                $view->vars['attr']['data-toggle-prefix'] = '.toggle_group_'.$options['toggle_prefix'];
                $view->vars['attr']['data-reverse-toggle-prefix'] = '.toggle_group_not_'.$options['toggle_prefix'];
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(
            [
                'toggle' => null,
                'toggle_prefix' => null,
                'toggle_group' => null,
            ]
        );

        $resolver->setAllowedTypes('toggle', ['null', 'string']);
        $resolver->setAllowedTypes('toggle_prefix', ['null', 'string']);
        $resolver->setAllowedTypes('toggle_group', ['null', 'string', 'array']);
    }

    /**
     * {@inheritdoc}
     */
    public function getExtendedType()
    {
        return FormType::class;
    }
}
{'fraction_non_alphanumeric': 0.15251046025104603, 'fraction_numerical': 0.0016736401673640166, 'mean_word_length': 2.4004267425320056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '4815324', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1297, 'n_words': 247}