コード例 #1
0
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if (!is_array($options['widget_addon'])) {
         throw new CreationException("The 'widget_addon' option must be an array");
     } else {
         $defaults = $this->getDefaultOptions($options);
         $options['widget_addon'] = array_merge($defaults['widget_addon'], $options['widget_addon']);
     }
     if (in_array('percent', $view->getVar('types'))) {
         if ($options['widget_addon']['text'] === null && $options['widget_addon']['icon'] === null) {
             $options['widget_addon']['text'] = '%';
         }
         if ($options['widget_addon']['type'] === null) {
             $options['widget_addon']['type'] = 'append';
         }
     }
     if (in_array('money', $view->getVar('types'))) {
         if ($options['widget_addon']['type'] === null) {
             $options['widget_addon']['type'] = 'prepend';
         }
     }
     if (($options['widget_addon']['text'] !== null || $options['widget_addon']['icon'] !== null) && $options['widget_addon']['type'] === null) {
         throw new \Exception('You must provide a "type" for widget_addon');
     }
     $view->addVars(array('widget_control_group' => $options['widget_control_group'], 'widget_controls' => $options['widget_controls'], 'widget_addon' => $options['widget_addon'], 'widget_prefix' => $options['widget_prefix'], 'widget_suffix' => $options['widget_suffix'], 'widget_type' => $options['widget_type'], 'widget_control_group_attr' => $options['widget_control_group_attr'], 'widget_controls_attr' => $options['widget_controls_attr']));
 }
コード例 #2
0
 /**
  * @param FormViewInterface $view
  * @param FormInterface     $form
  * @param array             $options
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $sonataAdmin = $form->getConfig()->getAttribute('sonata_admin');
     // avoid to add extra information not required by non admin field
     if ($form->getConfig()->getAttribute('sonata_admin_enabled', true)) {
         $sonataAdmin['value'] = $form->getData();
         // add a new block types, so the Admin Form element can be tweaked based on the admin code
         $types = $view->getVar('types');
         $baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
         $baseType = $types[count($types) - 1];
         $types[] = sprintf('%s_%s', $baseName, $baseType);
         $types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
         if ($sonataAdmin['block_name']) {
             $types[] = $sonataAdmin['block_name'];
         }
         $view->setVar('types', $types);
         $view->setVar('sonata_admin_enabled', true);
         $view->setVar('sonata_admin', $sonataAdmin);
         $attr = $view->getVar('attr', array());
         if (!isset($attr['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->setVar('attr', $attr);
     } else {
         $view->setVar('sonata_admin_enabled', false);
     }
     $view->setVar('sonata_admin', $sonataAdmin);
 }
コード例 #3
0
ファイル: ChoiceType.php プロジェクト: navassouza/symfony
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($options['expanded']) {
         // Radio buttons should have the same name as the parent
         $childName = $view->getVar('full_name');
         // Checkboxes should append "[]" to allow multiple selection
         if ($options['multiple']) {
             $childName .= '[]';
         }
         foreach ($view as $childView) {
             $childView->setVar('full_name', $childName);
         }
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $datas = json_decode($form->getViewData(), true);
     $value = '';
     if (!empty($datas)) {
         if ($options['multiple']) {
             foreach ($datas as $data) {
                 $value .= $data['label'] . ', ';
             }
         } else {
             $value = $datas['label'];
         }
     }
     $choices = array();
     foreach ($view->getVar('choices') as $choice) {
         $choices[] = array('value' => $choice->getValue(), 'label' => $choice->getLabel());
     }
     $view->setVar('choices', $choices)->setVar('autocompleter_value', $value)->setVar('route_name', $options['route_name'])->setVar('free_values', $options['free_values'])->setVar('full_block_name', 'genemu_jqueryautocompleter');
 }
コード例 #5
0
ファイル: CollectionType.php プロジェクト: laubosslink/lab
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($form->getConfig()->hasAttribute('prototype') && $view->getVar('prototype')->getVar('multipart')) {
         $view->setVar('multipart', true);
     }
 }