function it_changes_label_attribute_for(FormInterface $form, FormView $view, FormView $fileView)
 {
     $form->getName()->willReturn('file');
     $view->offsetGet('file')->willReturn($fileView);
     $view->vars = array('label_attr' => array());
     $fileView->vars = array('id' => 'form_file_file');
     $this->finishView($view, $form, array());
     expect($view->vars['label_attr']['for'])->toBe('form_file_file');
 }
Пример #2
0
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     /** @var FormView[] $fields */
     if ($view->offsetExists('submit_group')) {
         $fields = array($view->offsetGet('submit_group'));
         $view->offsetUnset('submit_group');
         $view->children = $view->children + $fields;
     }
     parent::finishView($view, $form, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $isManualEditGranted = $this->orderAddressSecurityProvider->isManualEditGranted($options['addressType']);
     foreach ($view->children as $child) {
         $child->vars['disabled'] = !$isManualEditGranted;
         $child->vars['required'] = false;
         unset($child->vars['attr']['data-validation'], $child->vars['attr']['data-required'], $child->vars['label_attr']['data-required']);
     }
     if ($view->offsetExists('accountAddress')) {
         $view->offsetGet('accountAddress')->vars['disabled'] = false;
     }
 }
Пример #4
0
 /**
  * render a field element from the FieldDescription
  *
  *
  * @throws InvalidArgumentException
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @param \Sumfony\Component\Form\FormView $formView
  * @param mixed $object
  * @param array $params
  * @return string
  */
 public function renderFormElement(FieldDescriptionInterface $fieldDescription, FormView $formView, $object, $params = array())
 {
     if (!$fieldDescription->getFieldName()) {
         return '';
     }
     if (!$formView->offsetExists($fieldDescription->getFieldName())) {
         throw new \RuntimeException(sprintf('No child named %s', $fieldDescription->getFieldName()));
     }
     $children = $formView->offsetGet($fieldDescription->getFieldName());
     if (in_array('hidden', $children->get('types'))) {
         return '';
     }
     // find the correct edit parameter
     //  edit   : standard | inline
     //  inline : natural | table
     $parentFieldDescription = $fieldDescription->getAdmin()->getParentFieldDescription();
     if (!$parentFieldDescription) {
         $params['edit'] = $fieldDescription->getOption('edit', 'standard');
         $params['inline'] = $fieldDescription->getOption('inline', 'natural');
         $base_template = sprintf('SonataAdminBundle:CRUD:base_%s_edit_field.html.twig', 'standard');
     } else {
         $params['edit'] = $parentFieldDescription->getOption('edit', 'standard');
         $params['inline'] = $parentFieldDescription->getOption('inline', 'natural');
         $base_template = sprintf('SonataAdminBundle:CRUD:base_%s_edit_field.html.twig', $params['edit']);
     }
     $template = $this->environment->loadTemplate($fieldDescription->getTemplate());
     return $this->output($fieldDescription, $template->render(array_merge($params, array('admin' => $fieldDescription->getAdmin(), 'object' => $object, 'field_description' => $fieldDescription, 'value' => $this->getValueFromFieldDescription($object, $fieldDescription, $params), 'field_element' => $children, 'base_template' => $fieldDescription->getOption('base_template', $base_template)))));
 }