/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form) { $name = $form->getName(); 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()->get('full_name'))) { $id = sprintf('%s_%s', $view->getParent()->get('id'), $name); $fullName = sprintf('%s[%s]', $parentFullName, $name); } else { $id = $name; $fullName = $name; } } else { // If this form node have empty name, set id to `form` // to avoid rendering `id=""` in html structure $id = $name ?: 'form'; $fullName = $name; } $types = array(); foreach ($form->getTypes() as $type) { $types[] = $type->getName(); } $view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('read_only', $form->isReadOnly())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain')); }
/** * Returns whether this form is read only. * * The content of a read-only form is displayed, but not allowed to be * modified. The validation of modified read-only forms should fail. * * Fields whose parents are read-only are considered read-only regardless of * their own state. * * @return Boolean */ public function isReadOnly() { if (null === $this->parent || !$this->parent->isReadOnly()) { return $this->readOnly; } return true; }
public function buildView(FormView $view, FormInterface $form) { if ($view->hasParent()) { $parentId = $view->getParent()->get('id'); $parentName = $view->getParent()->get('name'); $id = sprintf('%s_%s', $parentId, $form->getName()); $name = sprintf('%s[%s]', $parentName, $form->getName()); } else { $id = $form->getName(); $name = $form->getName(); } $view->set('form', $view); $view->set('id', $id); $view->set('name', $name); $view->set('errors', $form->getErrors()); $view->set('value', $form->getClientData()); $view->set('read_only', $form->isReadOnly()); $view->set('required', $form->isRequired()); $view->set('max_length', $form->getAttribute('max_length')); $view->set('size', null); $view->set('label', $form->getAttribute('label')); $view->set('multipart', false); $view->set('attr', array()); $types = array(); foreach (array_reverse((array) $form->getTypes()) as $type) { $types[] = $type->getName(); } $view->set('types', $types); }
public function mapFormToData(FormInterface $form, &$data) { if ($form->getAttribute('property_path') !== null && $form->isSynchronized() && !$form->isReadOnly()) { $propertyPath = $form->getAttribute('property_path'); // If the data is identical to the value in $data, we are // dealing with a reference $isReference = $form->getData() === $propertyPath->getValue($data); $byReference = $form->getAttribute('by_reference'); if (!(is_object($data) && $isReference && $byReference)) { $propertyPath->setValue($data, $form->getData()); } } }