コード例 #1
0
 /**
  * Adds a CSRF field to the root form view.
  *
  * @param FormView      $view The form view
  * @param FormInterface $form The form
  */
 public function buildViewBottomUp(FormView $view, FormInterface $form)
 {
     if (!$view->hasParent() && $view->hasChildren() && $form->hasAttribute('csrf_field_name')) {
         $name = $form->getAttribute('csrf_field_name');
         $csrfProvider = $form->getAttribute('csrf_provider');
         $intention = $form->getAttribute('csrf_intention');
         $factory = $form->getAttribute('csrf_factory');
         $data = $csrfProvider->generateCsrfToken($intention);
         $csrfForm = $factory->createNamed('hidden', $name, $data, array('property_path' => false));
         $view->addChild($csrfForm->createView($view));
     }
 }
コード例 #2
0
ファイル: DateType.php プロジェクト: rcambien/symfony
 /**
  * {@inheritdoc}
  */
 public function buildViewBottomUp(FormView $view, FormInterface $form)
 {
     $view->set('widget', $form->getAttribute('widget'));
     if ($view->hasChildren()) {
         $pattern = $form->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->set('date_pattern', $pattern);
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildViewBottomUp(FormView $view, FormInterface $form)
 {
     $view->set('widget', $form->getAttribute('widget'));
     $pattern = $form->getAttribute('formatter')->getPattern();
     $format = $pattern;
     if ($view->hasChildren()) {
         // 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->set('date_pattern', $pattern);
     $view->set('date_format', $this->convertJqueryDate($pattern));
     $view->set('change_month', $form->getAttribute('changemonth'));
     $view->set('change_year', $form->getAttribute('changeyear'));
     $view->set('min_date', $form->getAttribute('mindate'));
     $view->set('max_date', $form->getAttribute('maxdate'));
     $view->set('buttonImage', $form->getAttribute('buttonImage'));
     $view->set('locale', $this->session->getLocale());
 }