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

        $name = $form->getName();
        $readOnly = $options['read_only'];

        if ($view->parent) {
            if ('' === $name) {
                throw new LogicException('Form node with empty name can be used only as root form node.');
            }

            // Complex fields are read-only if they themselves or their parents are.
            if (!$readOnly) {
                $readOnly = $view->parent->vars['read_only'];
            }
        }

        $view->vars = array_replace($view->vars, array(
            'read_only'  => $readOnly,
            'errors'     => $form->getErrors(),
            'valid'      => $form->isSubmitted() ? $form->isValid() : true,
            'value'      => $form->getViewData(),
            'data'       => $form->getNormData(),
            'required'   => $form->isRequired(),
            'max_length' => $options['max_length'],
            'pattern'    => $options['pattern'],
            'size'       => null,
            'label_attr' => $options['label_attr'],
            'compound'   => $form->getConfig()->getCompound(),
            'method'     => $form->getConfig()->getMethod(),
            'action'     => $form->getConfig()->getAction(),
            'submitted'  => $form->isSubmitted(),
        ));
    }