/**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('no_results_text', $options['no_results_text']);
     $view->setVar('allow_single_deselect', $options['allow_single_deselect']);
     $view->setVar('disable_search_threshold', $options['disable_search_threshold']);
     $view->setVar('full_block_name', 'genemu_jquerychosen');
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('widget', $options['widget']);
     if ('single_text' === $options['widget']) {
         $view->setVar('type', 'datetime');
     }
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->addVars(array('multiple' => $options['multiple'], 'expanded' => $options['expanded'], 'preferred_choices' => $options['choice_list']->getPreferredViews(), 'choices' => $options['choice_list']->getRemainingViews(), 'separator' => '-------------------', 'empty_value' => null));
     // Check if the choices already contain the empty value
     // Only add the empty value option if this is not the case
     if (0 === count($options['choice_list']->getIndicesForValues(array('')))) {
         $view->setVar('empty_value', $options['empty_value']);
     }
     if ($options['multiple'] && !$options['expanded']) {
         // Add "[]" to the name in case a select tag with multiple options is
         // displayed. Otherwise only one of the selected options is sent in the
         // POST request.
         $view->setVar('full_name', $view->getVar('full_name') . '[]');
     }
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $configs = $options['configs'];
     $data = $form->getClientData();
     if (!empty($data)) {
         if (!$data instanceof Image) {
             $data = new Image($form->getAttribute('rootDir') . '/' . $data);
         }
         if ($data->hasThumbnail($this->selected)) {
             $thumbnail = $data->getThumbnail($this->selected);
             $view->setVar('thumbnail', array('file' => $configs['folder'] . '/' . $thumbnail->getFilename(), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()));
         }
         $value = $configs['folder'] . '/' . $data->getFilename();
         $view->setVar('value', $value)->setVar('file', $value)->setVar('width', $data->getWidth())->setVar('height', $data->getHeight());
     }
     $view->setVar('filters', $this->filters);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $configs = $options['configs'];
     $years = $options['years'];
     $configs['dateFormat'] = 'yy-mm-dd';
     if ('single_text' === $options['widget']) {
         $formatter = $form->getAttribute('formatter');
         $configs['dateFormat'] = $this->getJavascriptPattern($formatter);
     }
     $view->setVar('min_year', min($years))->setVar('max_year', max($years))->setVar('configs', $configs)->setVar('culture', $options['culture']);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('widget', $options['widget']);
     // Change the input to a HTML5 date input if
     //  * the widget is set to "single_text"
     //  * the format matches the one expected by HTML5
     if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
         $view->setVar('type', 'date');
     }
     if ($form->getConfig()->hasAttribute('formatter')) {
         $pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
         // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
         // lookup various formats at http://userguide.icu-project.org/formatparse/datetime
         if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
             $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
         } else {
             // default fallback
             $pattern = '{{ year }}-{{ month }}-{{ day }}';
         }
         $view->setVar('date_pattern', $pattern);
     }
 }
 /**
  * {@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');
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $datas = json_decode($form->getClientData(), true);
     $value = '';
     if (false === empty($datas)) {
         if (true === $form->getAttribute('multiple')) {
             foreach ($datas as $data) {
                 $value .= $data['label'] . ', ';
             }
         } else {
             $value = $datas['label'];
         }
     }
     $view->setVar('tokeninput_value', $value)->setVar('route_name', $form->getAttribute('route_name'));
     foreach ($this->_availableTokeninputOptions as $option) {
         if ($form->hasAttribute($option)) {
             $view->set($option, $form->getAttribute($option));
         }
     }
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $value = $form->getViewData();
     // set string representation
     if (true === $value) {
         $value = 'true';
     } elseif (false === $value) {
         $value = 'false';
     } elseif (null === $value) {
         $value = 'null';
     } elseif (is_array($value)) {
         $value = implode(', ', $value);
     } elseif ($value instanceof \DateTime) {
         $value = $value->format('Y-m-d H:i:s');
     } elseif (is_object($value)) {
         if (method_exists($value, '__toString')) {
             $value = $value->__toString();
         } else {
             $value = get_class($value);
         }
     }
     $view->setVar('value', (string) $value);
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($options['always_empty'] || !$form->isBound()) {
         $view->setVar('value', '');
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('widget', $options['widget']);
     // Change the input to a HTML5 date input if
     //  * the widget is set to "single_text"
     //  * the format matches the one expected by HTML5
     if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
         $view->setVar('type', 'datetime');
     }
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('type', 'hidden')->setVar('value', $form->getViewData())->setVar('multiple', $options['multiple'])->setVar('configs', $options['configs']);
 }
Exemplo n.º 14
0
    /**
     * {@inheritdoc}
     */
    public function finishView(FormViewInterface $view, FormInterface $form, array $options)
    {
        $view->setVar('widget', $options['widget']);

        if ('single_text' === $options['widget']) {
            $view->setVar('type', 'date');
        }

        if (count($view) > 0) {
            $pattern = $form->getConfig()->getAttribute('formatter')->getPattern();

            // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
            // lookup various formats at http://userguide.icu-project.org/formatparse/datetime
            if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
                $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
            } else {
                // default fallback
                $pattern = '{{ year }}-{{ month }}-{{ day }}';
            }

            $view->setVar('date_pattern', $pattern);
        }
    }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('configs', $options['configs']);
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->addVars(array('widget' => $options['widget'], 'with_seconds' => $options['with_seconds']));
     if ('single_text' === $options['widget']) {
         $view->setVar('type', 'time');
     }
 }
Exemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($form->getConfig()->hasAttribute('prototype') && $view->getVar('prototype')->getVar('multipart')) {
         $view->setVar('multipart', true);
     }
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $multipart = false;
     foreach ($view as $child) {
         if ($child->getVar('multipart')) {
             $multipart = true;
             break;
         }
     }
     $view->setVar('multipart', $multipart);
 }
Exemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('pattern', null);
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('widget', $form->getAttribute('widget'))->setVar('configs', $form->getAttribute('configs'));
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('allow_single_deselect', $options['allow_single_deselect']);
     $view->setVar('disable_search_threshold', $options['disable_search_threshold']);
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('money_pattern', self::getPattern($options['currency']));
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('multipart', true);
 }