Symfony\Component\Form\TimeField::configure PHP Method

configure() protected method

{@inheritDoc}
protected configure ( )
    protected function configure()
    {
        $this->addOption('hours', range(0, 23));
        $this->addOption('minutes', range(0, 59));
        $this->addOption('seconds', range(0, 59));
        $this->addOption('widget', self::CHOICE, self::$widgets);
        $this->addOption('type', self::DATETIME, self::$types);
        $this->addOption('data_timezone', 'UTC');
        $this->addOption('user_timezone', 'UTC');
        $this->addOption('with_seconds', false);

        if ($this->getOption('widget') == self::INPUT) {
            $this->add(new TextField('hour', array('max_length' => 2)));
            $this->add(new TextField('minute', array('max_length' => 2)));

            if ($this->getOption('with_seconds')) {
                $this->add(new TextField('second', array('max_length' => 2)));
            }
        } else {
            $this->add(new ChoiceField('hour', array(
                'choices' => $this->generatePaddedChoices($this->getOption('hours'), 2),
            )));
            $this->add(new ChoiceField('minute', array(
                'choices' => $this->generatePaddedChoices($this->getOption('minutes'), 2),
            )));

            if ($this->getOption('with_seconds')) {
                $this->add(new ChoiceField('second', array(
                    'choices' => $this->generatePaddedChoices($this->getOption('seconds'), 2),
                )));
            }
        }

        $fields = array('hour', 'minute');

        if ($this->getOption('with_seconds')) {
            $fields[] = 'second';
        }

        if ($this->getOption('type') == self::STRING) {
            $this->setNormalizationTransformer(new ReversedTransformer(
                new DateTimeToStringTransformer(array(
                    'format' => 'H:i:s',
                    'input_timezone' => $this->getOption('data_timezone'),
                    'output_timezone' => $this->getOption('data_timezone'),
                ))
            ));
        } else if ($this->getOption('type') == self::TIMESTAMP) {
            $this->setNormalizationTransformer(new ReversedTransformer(
                new DateTimeToTimestampTransformer(array(
                    'input_timezone' => $this->getOption('data_timezone'),
                    'output_timezone' => $this->getOption('data_timezone'),
                ))
            ));
        } else if ($this->getOption('type') === self::RAW) {
            $this->setNormalizationTransformer(new ReversedTransformer(
                new DateTimeToArrayTransformer(array(
                    'input_timezone' => $this->getOption('data_timezone'),
                    'output_timezone' => $this->getOption('data_timezone'),
                    'fields' => $fields,
                ))
            ));
        }

        $this->setValueTransformer(new DateTimeToArrayTransformer(array(
            'input_timezone' => $this->getOption('data_timezone'),
            'output_timezone' => $this->getOption('user_timezone'),
            // if the field is rendered as choice field, the values should be trimmed
            // of trailing zeros to render the selected choices correctly
            'pad' => $this->getOption('widget') == self::INPUT,
            'fields' => $fields,
        )));
    }