/**
  * @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);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $value = $form->getClientData();
     // set string representation
     if (true === $value) {
         $value = 'true';
     } else {
         if (false === $value) {
             $value = 'false';
         } else {
             if (null === $value) {
                 $value = 'null';
             } else {
                 if (is_array($value)) {
                     $value = implode(', ', $value);
                 } else {
                     if ($value instanceof \DateTime) {
                         $value = $value->format('Y-m-d H:i:s');
                     } else {
                         if (is_object($value)) {
                             if (method_exists($value, '__toString')) {
                                 $value = $value->__toString();
                             } else {
                                 $value = get_class($value);
                             }
                         }
                     }
                 }
             }
         }
     }
     $view->set('value', (string) $value);
 }
Example #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');
     }
 }
Example #4
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');
     }
 }
Example #5
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');
 }
 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']));
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $configs = $form->getAttribute('configs');
     $datas = $form->getClientData();
     if (!empty($datas)) {
         if ($form->getAttribute('multiple')) {
             $datas = is_scalar($datas) ? explode(',', $datas) : $datas;
             $value = array();
             foreach ($datas as $data) {
                 if (!$data instanceof File) {
                     $data = new File($form->getAttribute('rootDir') . '/' . $data);
                 }
                 $value[] = $configs['folder'] . '/' . $data->getFilename();
             }
             $value = implode(',', $value);
         } else {
             if (!$datas instanceof File) {
                 $datas = new File($form->getAttribute('rootDir') . '/' . $datas);
             }
             $value = $configs['folder'] . '/' . $datas->getFilename();
         }
         $view->set('value', $value);
     }
     $view->set('type', 'hidden')->set('configs', $form->getAttribute('configs'));
 }
 /**
  * Adds a CSRF field to the root form view.
  *
  * @param FormView      $view The form view
  * @param FormInterface $form The form
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($options['csrf_protection'] && !$view->hasParent() && $options['compound']) {
         $factory = $form->getConfig()->getAttribute('csrf_factory');
         $data = $options['csrf_provider']->generateCsrfToken($options['intention']);
         $csrfForm = $factory->createNamed($options['csrf_field_name'], 'hidden', $data, array('mapped' => false));
         $view->add($csrfForm->createView($view));
     }
 }
Example #9
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']);
 }
Example #10
0
 /**
  * {@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);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $datas = json_decode($form->getClientData(), true);
     $value = '';
     if (!empty($datas)) {
         if ($form->getAttribute('multiple')) {
             foreach ($datas as $data) {
                 $value .= $data['label'] . ', ';
             }
         } else {
             $value = $datas['label'];
         }
     }
     $view->set('autocompleter_value', $value)->set('route_name', $form->getAttribute('route_name'))->set('freeValues', $form->getAttribute('freeValues'));
 }
Example #12
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);
 }
Example #13
0
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $fingerprint = null;
     if ($options['keep_value'] && $this->session->has($this->key . '_fingerprint')) {
         $fingerprint = $this->session->get($this->key . '_fingerprint');
     }
     $generator = new CaptchaGenerator($this->generateCaptchaValue(), $options['image_folder'], $options['web_path'], $options['gc_freq'], $options['expiration'], $options['font'], $fingerprint, $options['quality']);
     if ($options['as_file']) {
         $captchaCode = $generator->getFile($options['width'], $options['height']);
     } else {
         $captchaCode = $generator->getCode($options['width'], $options['height']);
     }
     if ($options['keep_value']) {
         $this->session->set($this->key . '_fingerprint', $generator->getFingerprint());
     }
     $view->addVars(array('captcha_width' => $options['width'], 'captcha_height' => $options['height'], 'captcha_code' => $captchaCode, 'value' => ''));
 }
 /**
  * {@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');
 }
Example #15
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);
 }
 /**
  * {@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->set('tokeninput_value', $value)->set('route_name', $form->getAttribute('route_name'));
     foreach ($this->_availableTokeninputOptions as $option) {
         if ($form->hasAttribute($option)) {
             $view->set($option, $form->getAttribute($option));
         }
     }
 }
Example #17
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);
     }
 }
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($options['widget_add_btn'] != null && !is_array($options['widget_add_btn'])) {
         throw new FormException('The "widget_add_btn" option must be an "array".');
     } elseif ($options['widget_add_btn'] != null) {
         if (isset($options['widget_add_btn']['attr']) && !is_array($options['widget_add_btn']['attr'])) {
             throw new FormException('The "widget_add_btn.attr" option must be an "array".');
         }
         if (!isset($options['widget_add_btn']['attr'])) {
             $options['widget_add_btn']['attr'] = $this->options['widget_add_btn']['attr'];
         }
         if (!isset($options['widget_add_btn']['label']) && !isset($options['widget_add_btn']['icon'])) {
             throw new FormException('Provide either "icon" or "label" to "widget_add_btn"');
         }
         if (!isset($options['widget_add_btn']['icon']) && $this->options['widget_add_btn']['icon'] != null) {
             $options['widget_add_btn']['icon'] = $this->options['widget_add_btn']['icon'];
         }
     }
     if ($options['widget_remove_btn'] != null && !is_array($options['widget_remove_btn'])) {
         throw new FormException('The "widget_remove_btn" option must be an "array".');
     } elseif ($options['widget_remove_btn'] != null) {
         if (isset($options['widget_remove_btn']) && !is_array($options['widget_remove_btn'])) {
             throw new FormException('The "widget_remove_btn" option must be an "array".');
         }
         if (!isset($options['widget_remove_btn']['attr'])) {
             $options['widget_remove_btn']['attr'] = $this->options['widget_remove_btn']['attr'];
         }
         if (!isset($options['widget_remove_btn']['label']) && !isset($options['widget_remove_btn']['icon'])) {
             throw new FormException('Provide either "icon" or "label" to "widget_remove_btn"');
         }
         if (!isset($options['widget_remove_btn']['icon']) && $this->options['widget_remove_btn']['icon'] != null) {
             $options['widget_remove_btn']['icon'] = $this->options['widget_remove_btn']['icon'];
         }
     }
     $view->addVars(array('widget_add_btn' => $options['widget_add_btn'], 'widget_remove_btn' => $options['widget_remove_btn']));
 }
Example #19
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);
     }
 }
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->addVars(array('render_fieldset' => $options['render_fieldset'], 'show_legend' => $options['show_legend'], 'show_child_legend' => $options['show_child_legend'], 'label_render' => $options['label_render'], 'render_required_asterisk' => $options['render_required_asterisk']));
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->set('configs', array('elements' => array()))->set('map', $form->getAttribute('map'));
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->addVars(array('value' => $options['value'], 'checked' => null !== $form->getViewData()));
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('configs', $options['configs']);
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('multipart', true);
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->set('configs', $form->getAttribute('configs'));
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->addVars(array('suggestions' => $options['suggestions'], 'multiple' => $options['multiple'], 'route_name' => $options['route_name']));
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->setVar('money_pattern', self::getPattern($options['currency']));
 }
Example #28
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $captcha = $form->getAttribute('captcha');
     $view->set('value', '')->set('position', $form->getAttribute('position'))->set('src', $captcha->getBase64($form->getAttribute('format')))->set('width', $captcha->getWidth())->set('height', $captcha->getHeight());
 }
Example #29
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     if ($options['always_empty'] || !$form->isBound()) {
         $view->setVar('value', '');
     }
 }
Example #30
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $view->set('allow_single_deselect', $form->getAttribute('allow_single_deselect'));
 }