<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace FormBundle\Form\Admin\Form;

use CommonBundle\Component\Form\FieldsetInterface,
    CommonBundle\Entity\General\Language;

/**
 * Add Form
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class Add extends \CommonBundle\Component\Form\Admin\Form\Tabbable
{
    protected $hydrator = 'FormBundle\Hydrator\Node\Form';

    public function init()
    {
        $this->add(array(
            'type'       => 'select',
            'name'       => 'type',
            'label'      => 'Type',
            'required'   => true,
            'attributes' => array(
                'id'      => 'form_type',
                'options' => array('form' => 'Form', 'doodle' => 'Doodle'),
            ),
        ));

        parent::init();

        $this->add(array(
            'type'       => 'datetime',
            'name'       => 'start_date',
            'label'      => 'Start Date',
            'required'   => true,
        ));

        $this->add(array(
            'type'       => 'datetime',
            'name'       => 'end_date',
            'label'      => 'End Date',
            'required'   => true,
            'options'    => array(
                'input' => array(
                    'validators' => array(
                        array(
                            'name' => 'date_compare',
                            'options' => array(
                                'first_date' => 'start_date',
                                'format' => 'd/m/Y H:i',
                            ),
                        ),
                    ),
                ),
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'active',
            'label'      => 'Active',
        ));

        $this->add(array(
            'type'       => 'text',
            'name'       => 'max',
            'label'      => 'Total Max Entries',
            'attributes' => array(
                'class'     => 'form_element',
                'data-help' => 'The maximum number of form submittions possible.',
            ),
            'options'    => array(
                'input' => array(
                    'filters'  => array(
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'digits',
                        ),
                    ),
                ),
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'non_member',
            'label'      => 'Without Login',
            'attributes' => array(
                'data-help' => 'Allow users to submit this form without login. A name and email field will be added as first fields of this form.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'editable_by_user',
            'label'      => 'Editable By User',
            'attributes' => array(
                'data-help' => 'The users are allowed to edit the info of previously submitted entries. This will also enable the "Save as Concept" button.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'send_guest_login_mail',
            'label'      => 'Send Guest Login Mail',
            'attributes' => array(
                'id'        => 'send_guest_login_mail',
                'data-help' => 'Send a mail to guests after submitting form to login later and edit/view their submission.<br>For this option the confirmation mail must be enabled!',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'names_visible_for_others',
            'label'      => 'Names Visible For Others',
            'attributes' => array(
                'class'     => 'doodle_element',
                'data-help' => 'Display the name of other person registered for slots in this doodle.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'multiple',
            'label'      => 'Multiple Entries Per Person',
            'attributes' => array(
                'data-help' => 'The maximum number of form submittions possible for each user.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'mail',
            'label'      => 'Send Confirmation Mail',
            'attributes' => array(
                'id' => 'mail',
            ),
        ));

        $this->add(array(
            'type'       => 'form_form_mail_add',
            'name'       => 'mail_form',
            'label'      => 'Mail',
            'attributes' => array(
                'id' => 'mail_form',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'reminder_mail',
            'label'      => 'Send Reminder Mail',
            'attributes' => array(
                'id'        => 'reminder_mail',
                'class'     => 'doodle_element',
                'data-help' => 'This mail will be sent the day before the timeslot starts. <br><br> If the slot is on Tuesday, the user will receive an email on Sunday morning.',
            ),
        ));

        $this->add(array(
            'type'       => 'form_form_mail_add',
            'name'       => 'reminder_mail_form',
            'label'      => 'Reminder Mail',
            'attributes' => array(
                'id'    => 'reminder_mail_form',
            ),
        ));

        $this->addSubmit('Add', 'form_add');

        $hydrator = $this->getHydrator();
        $this->populateValues($hydrator->extract(null));
    }

    protected function addTab(FieldsetInterface $container, Language $language, $isDefault)
    {
        $container->add(array(
            'type'       => 'text',
            'name'       => 'title',
            'label'      => 'Title',
            'required'   => $isDefault,
            'attributes' => array(
                'width' => '400px',
            ),
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));

        $container->add(array(
            'type'       => 'textarea',
            'name'       => 'introduction',
            'label'      => 'Introduction',
            'required'   => $isDefault,
            'attributes' => array(
                'class' => 'md',
                'row'   => 20,
            ),
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));

        $container->add(array(
            'type'       => 'text',
            'name'       => 'submittext',
            'label'      => 'Submit Button Text',
            'required'   => $isDefault,
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));

        $container->add(array(
            'type'       => 'text',
            'name'       => 'updatetext',
            'label'      => 'Update Button Text',
            'required'   => $isDefault,
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));
    }

    public function getInputFilterSpecification()
    {
        $specs = parent::getInputFilterSpecification();

        if (!$this->get('mail')->getValue()) {
            unset($specs['mail_form']);
        }

        if (!$this instanceof Edit || $this->isDoodle()) {
            if (!$this->get('reminder_mail')->getValue()) {
                unset($specs['reminder_mail_form']);
            }
        }

        return $specs;
    }
}
<commit_msg>make from field required again<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace FormBundle\Form\Admin\Form;

use CommonBundle\Component\Form\FieldsetInterface,
    CommonBundle\Entity\General\Language;

/**
 * Add Form
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>us.cc>
 */
class Add extends \CommonBundle\Component\Form\Admin\Form\Tabbable
{
    protected $hydrator = 'FormBundle\Hydrator\Node\Form';

    public function init()
    {
        $this->add(array(
            'type'       => 'select',
            'name'       => 'type',
            'label'      => 'Type',
            'required'   => true,
            'attributes' => array(
                'id'      => 'form_type',
                'options' => array('form' => 'Form', 'doodle' => 'Doodle'),
            ),
        ));

        parent::init();

        $this->add(array(
            'type'       => 'datetime',
            'name'       => 'start_date',
            'label'      => 'Start Date',
            'required'   => true,
        ));

        $this->add(array(
            'type'       => 'datetime',
            'name'       => 'end_date',
            'label'      => 'End Date',
            'required'   => true,
            'options'    => array(
                'input' => array(
                    'validators' => array(
                        array(
                            'name' => 'date_compare',
                            'options' => array(
                                'first_date' => 'start_date',
                                'format' => 'd/m/Y H:i',
                            ),
                        ),
                    ),
                ),
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'active',
            'label'      => 'Active',
        ));

        $this->add(array(
            'type'       => 'text',
            'name'       => 'max',
            'label'      => 'Total Max Entries',
            'attributes' => array(
                'class'     => 'form_element',
                'data-help' => 'The maximum number of form submittions possible.',
            ),
            'options'    => array(
                'input' => array(
                    'filters'  => array(
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'digits',
                        ),
                    ),
                ),
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'non_member',
            'label'      => 'Without Login',
            'attributes' => array(
                'data-help' => 'Allow users to submit this form without login. A name and email field will be added as first fields of this form.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'editable_by_user',
            'label'      => 'Editable By User',
            'attributes' => array(
                'data-help' => 'The users are allowed to edit the info of previously submitted entries. This will also enable the "Save as Concept" button.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'send_guest_login_mail',
            'label'      => 'Send Guest Login Mail',
            'attributes' => array(
                'id'        => 'send_guest_login_mail',
                'data-help' => 'Send a mail to guests after submitting form to login later and edit/view their submission.<br>For this option the confirmation mail must be enabled!',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'names_visible_for_others',
            'label'      => 'Names Visible For Others',
            'attributes' => array(
                'class'     => 'doodle_element',
                'data-help' => 'Display the name of other person registered for slots in this doodle.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'multiple',
            'label'      => 'Multiple Entries Per Person',
            'attributes' => array(
                'data-help' => 'The maximum number of form submittions possible for each user.',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'mail',
            'label'      => 'Send Confirmation Mail',
            'attributes' => array(
                'id' => 'mail',
            ),
        ));

        $this->add(array(
            'type'       => 'form_form_mail_add',
            'name'       => 'mail_form',
            'label'      => 'Mail',
            'required'   => true,
            'attributes' => array(
                'id' => 'mail_form',
            ),
        ));

        $this->add(array(
            'type'       => 'checkbox',
            'name'       => 'reminder_mail',
            'label'      => 'Send Reminder Mail',
            'attributes' => array(
                'id'        => 'reminder_mail',
                'class'     => 'doodle_element',
                'data-help' => 'This mail will be sent the day before the timeslot starts. <br><br> If the slot is on Tuesday, the user will receive an email on Sunday morning.',
            ),
        ));

        $this->add(array(
            'type'       => 'form_form_mail_add',
            'name'       => 'reminder_mail_form',
            'label'      => 'Reminder Mail',
            'required'   => true,
            'attributes' => array(
                'id'    => 'reminder_mail_form',
            ),
        ));

        $this->addSubmit('Add', 'form_add');

        $hydrator = $this->getHydrator();
        $this->populateValues($hydrator->extract(null));
    }

    protected function addTab(FieldsetInterface $container, Language $language, $isDefault)
    {
        $container->add(array(
            'type'       => 'text',
            'name'       => 'title',
            'label'      => 'Title',
            'required'   => $isDefault,
            'attributes' => array(
                'width' => '400px',
            ),
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));

        $container->add(array(
            'type'       => 'textarea',
            'name'       => 'introduction',
            'label'      => 'Introduction',
            'required'   => $isDefault,
            'attributes' => array(
                'class' => 'md',
                'row'   => 20,
            ),
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));

        $container->add(array(
            'type'       => 'text',
            'name'       => 'submittext',
            'label'      => 'Submit Button Text',
            'required'   => $isDefault,
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));

        $container->add(array(
            'type'       => 'text',
            'name'       => 'updatetext',
            'label'      => 'Update Button Text',
            'required'   => $isDefault,
            'options'    => array(
                'input' => array(
                    'filters' => array(
                        array('name' => 'StringTrim'),
                    ),
                ),
            ),
        ));
    }

    public function getInputFilterSpecification()
    {
        $specs = parent::getInputFilterSpecification();

        if (!$this->get('mail')->getValue()) {
            unset($specs['mail_form']);
        }

        if (!$this instanceof Edit || $this->isDoodle()) {
            if (!$this->get('reminder_mail')->getValue()) {
                unset($specs['reminder_mail_form']);
            }
        }

        return $specs;
    }
}

{'fraction_non_alphanumeric': 0.1498428026049854, 'fraction_numerical': 0.0005614192679092747, 'mean_word_length': 1.1728470358624055, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 387, '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': '3093963', 'n_tokens_mistral': 4809, 'n_tokens_neox': 4630, 'n_words': 1058}