/** * {@inheritdoc} */ public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $name = $form->getName(); $readOnly = $options['read_only']; $translationDomain = $options['translation_domain']; if ($view->hasParent()) { if ('' === $name) { throw new FormException('Form node with empty name can be used only as root form node.'); } if ('' !== ($parentFullName = $view->getParent()->getVar('full_name'))) { $id = sprintf('%s_%s', $view->getParent()->getVar('id'), $name); $fullName = sprintf('%s[%s]', $parentFullName, $name); } else { $id = $name; $fullName = $name; } // Complex fields are read-only if themselves or their parent is. $readOnly = $readOnly || $view->getParent()->getVar('read_only'); if (!$translationDomain) { $translationDomain = $view->getParent()->getVar('translation_domain'); } } else { $id = $name; $fullName = $name; // Strip leading underscores and digits. These are allowed in // form names, but not in HTML4 ID attributes. // http://www.w3.org/TR/html401/struct/global.html#adef-id $id = ltrim($id, '_0123456789'); } $types = array(); foreach ($form->getConfig()->getTypes() as $type) { $types[] = $type->getName(); } if (!$translationDomain) { $translationDomain = 'messages'; } $view->addVars(array('form' => $view, 'id' => $id, 'name' => $name, 'full_name' => $fullName, 'read_only' => $readOnly, 'errors' => $form->getErrors(), 'valid' => $form->isBound() ? $form->isValid() : true, 'value' => $form->getViewData(), 'disabled' => $form->isDisabled(), 'required' => $form->isRequired(), 'max_length' => $options['max_length'], 'pattern' => $options['pattern'], 'size' => null, 'label' => $options['label'] ?: $this->humanize($form->getName()), 'multipart' => false, 'attr' => $options['attr'], 'label_attr' => $options['label_attr'], 'compound' => $options['compound'], 'types' => $types, 'translation_domain' => $translationDomain)); }