當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FormBuilderInterface::addModelTransformer方法代碼示例

本文整理匯總了PHP中Symfony\Component\Form\FormBuilderInterface::addModelTransformer方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormBuilderInterface::addModelTransformer方法的具體用法?PHP FormBuilderInterface::addModelTransformer怎麽用?PHP FormBuilderInterface::addModelTransformer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Form\FormBuilderInterface的用法示例。


在下文中一共展示了FormBuilderInterface::addModelTransformer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $transformer = new ManyRelatedTransformer($this->doctrineRegistry, $options['entityName']);
     $viewTransformer = new ArrayToStringTransformer();
     $builder->addModelTransformer($transformer);
     $builder->addViewTransformer($viewTransformer);
 }
開發者ID:profcab,項目名稱:ilios,代碼行數:7,代碼來源:ManyRelatedType.php

示例2: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $format = $options['format'];
     $pattern = null;
     $allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
     // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
     if (!in_array($format, $allowedFormatOptionValues, true)) {
         if (is_string($format)) {
             $format = self::DEFAULT_FORMAT;
             $pattern = $options['format'];
         } else {
             throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
         }
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
     $formatter->setLenient(false);
     $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
     }
     $builder->setAttribute('date_pattern', $formatter->getPattern());
 }
開發者ID:senthilkumar3282,項目名稱:LyraAdminBundle,代碼行數:26,代碼來源:DatePickerType.php

示例3: buildForm

 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  *
  * @throws NotAllowedClassNameException
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['is_condition']) {
         $builder->addModelTransformer($this->conditionToReferenceKeywordTransformer);
     } else {
         $builder->addModelTransformer($this->csvToReferenceKeywordTransformer);
     }
 }
開發者ID:open-orchestra,項目名稱:open-orchestra-cms-bundle,代碼行數:14,代碼來源:KeywordsChoiceType.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$options['multiple']) {
         $builder->addModelTransformer(new ResourceToIdentifierTransformer($this->resourceRepositoryRegistry->get($options['resource']), $options['choice_value']));
     }
     if ($options['multiple']) {
         $builder->addModelTransformer(new RecursiveTransformer(new ResourceToIdentifierTransformer($this->resourceRepositoryRegistry->get($options['resource']), $options['choice_value'])))->addViewTransformer(new CollectionToStringTransformer(','));
     }
 }
開發者ID:NeverResponse,項目名稱:Sylius,代碼行數:12,代碼來源:ResourceAutocompleteChoiceType.php

示例5: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['multiple']) {
         $builder->addModelTransformer(new RecursiveTransformer(new ProductTaxonToTaxonTransformer($this->productTaxonFactory)));
     }
     if (!$options['multiple']) {
         $builder->addModelTransformer(new ProductTaxonToTaxonTransformer($this->productTaxonFactory));
     }
 }
開發者ID:NeverResponse,項目名稱:Sylius,代碼行數:12,代碼來源:ProductTaxonAutocompleteChoiceType.php

示例6: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $format = $options['format'];
     $pattern = null;
     $allowedFormats = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
     // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
     if (!in_array($format, $allowedFormats, true)) {
         if (is_string($format)) {
             $format = self::DEFAULT_FORMAT;
             $pattern = $options['format'];
         } else {
             throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
         }
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
     $formatter->setLenient(false);
     if ('single_text' === $options['widget']) {
         $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array();
         if ('choice' === $options['widget']) {
             if (is_array($options['empty_value'])) {
                 $options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']);
             } else {
                 $options['empty_value'] = array('year' => $options['empty_value'], 'month' => $options['empty_value'], 'day' => $options['empty_value']);
             }
             $years = $months = $days = array();
             foreach ($options['years'] as $year) {
                 $years[$year] = str_pad($year, 4, '0', STR_PAD_LEFT);
             }
             foreach ($options['months'] as $month) {
                 $months[$month] = str_pad($month, 2, '0', STR_PAD_LEFT);
             }
             foreach ($options['days'] as $day) {
                 $days[$day] = str_pad($day, 2, '0', STR_PAD_LEFT);
             }
             // Only pass a subset of the options to children
             $yearOptions = array('choices' => $years, 'empty_value' => $options['empty_value']['year']);
             $monthOptions = array('choices' => $this->formatMonths($formatter, $months), 'empty_value' => $options['empty_value']['month']);
             $dayOptions = array('choices' => $days, 'empty_value' => $options['empty_value']['day']);
             // Append generic carry-along options
             foreach (array('required', 'translation_domain') as $passOpt) {
                 $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt];
             }
         }
         $builder->add('year', $options['widget'], $yearOptions)->add('month', $options['widget'], $monthOptions)->add('day', $options['widget'], $dayOptions)->addViewTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
     }
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
     }
     $builder->setAttribute('formatter', $formatter);
 }
開發者ID:laubosslink,項目名稱:lab,代碼行數:59,代碼來源:DateType.php

示例7: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $parts = array('hour', 'minute');
     $format = 'H:i';
     if ($options['with_seconds']) {
         $format = 'H:i:s';
         $parts[] = 'second';
     }
     if ('single_text' === $options['widget']) {
         $builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format));
     } else {
         $hourOptions = $minuteOptions = $secondOptions = array('error_bubbling' => true);
         if ('choice' === $options['widget']) {
             $hours = $minutes = array();
             foreach ($options['hours'] as $hour) {
                 $hours[$hour] = str_pad($hour, 2, '0', STR_PAD_LEFT);
             }
             foreach ($options['minutes'] as $minute) {
                 $minutes[$minute] = str_pad($minute, 2, '0', STR_PAD_LEFT);
             }
             // Only pass a subset of the options to children
             $hourOptions['choices'] = $hours;
             $hourOptions['empty_value'] = $options['empty_value']['hour'];
             $minuteOptions['choices'] = $minutes;
             $minuteOptions['empty_value'] = $options['empty_value']['minute'];
             if ($options['with_seconds']) {
                 $seconds = array();
                 foreach ($options['seconds'] as $second) {
                     $seconds[$second] = str_pad($second, 2, '0', STR_PAD_LEFT);
                 }
                 $secondOptions['choices'] = $seconds;
                 $secondOptions['empty_value'] = $options['empty_value']['second'];
             }
             // Append generic carry-along options
             foreach (array('required', 'translation_domain') as $passOpt) {
                 $hourOptions[$passOpt] = $minuteOptions[$passOpt] = $options[$passOpt];
                 if ($options['with_seconds']) {
                     $secondOptions[$passOpt] = $options[$passOpt];
                 }
             }
         }
         $builder->add('hour', $options['widget'], $hourOptions)->add('minute', $options['widget'], $minuteOptions);
         if ($options['with_seconds']) {
             $builder->add('second', $options['widget'], $secondOptions);
         }
         $builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget']));
     }
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'H:i:s')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], $parts)));
     }
 }
開發者ID:nathanlon,項目名稱:symfony,代碼行數:58,代碼來源:TimeType.php

示例8: buildForm

 /**
  * (non-PHPdoc)
  * @see Symfony\Component\Form.AbstractType::buildForm()
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addViewTransformer(new DateTimeToStringTransformer($options['date_timezone'], $options['user_timezone'], $options['datetime_format']));
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['date_timezone'], $options['date_timezone'], $options['datetime_format'])));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['date_timezone'], $options['date_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['date_timezone'], $options['date_timezone'], $options['parts'])));
     }
 }
開發者ID:firano,項目名稱:form-bundle,代碼行數:15,代碼來源:DateTimePickerType.php

示例9: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $dateFormat = is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT;
     $timeFormat = \IntlDateFormatter::NONE;
     $calendar = \IntlDateFormatter::GREGORIAN;
     $pattern = is_string($options['format']) ? $options['format'] : null;
     if (!in_array($dateFormat, self::$acceptedFormats, true)) {
         throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
     }
     if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) {
         throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
     }
     if ('single_text' === $options['widget']) {
         $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['model_timezone'], $options['view_timezone'], $dateFormat, $timeFormat, $calendar, $pattern));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array('error_bubbling' => true);
         $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, null, $calendar, $pattern);
         // new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
         if (!$formatter) {
             throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code());
         }
         $formatter->setLenient(false);
         if ('choice' === $options['widget']) {
             // Only pass a subset of the options to children
             $yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
             $yearOptions['choices_as_values'] = true;
             $yearOptions['placeholder'] = $options['placeholder']['year'];
             $yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year'];
             $monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
             $monthOptions['choices_as_values'] = true;
             $monthOptions['placeholder'] = $options['placeholder']['month'];
             $monthOptions['choice_translation_domain'] = $options['choice_translation_domain']['month'];
             $dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
             $dayOptions['choices_as_values'] = true;
             $dayOptions['placeholder'] = $options['placeholder']['day'];
             $dayOptions['choice_translation_domain'] = $options['choice_translation_domain']['day'];
         }
         // Append generic carry-along options
         foreach (array('required', 'translation_domain') as $passOpt) {
             $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt];
         }
         $builder->add('year', self::$widgets[$options['widget']], $yearOptions)->add('month', self::$widgets[$options['widget']], $monthOptions)->add('day', self::$widgets[$options['widget']], $dayOptions)->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')))->setAttribute('formatter', $formatter);
     }
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day'))));
     }
 }
開發者ID:ron-testam,項目名稱:symfony,代碼行數:54,代碼來源:DateType.php

示例10: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entityManager = $options['em'];
     $dataClass = $options['tag_class'];
     $transformer = new TagTransformer($entityManager, $dataClass);
     $builder->addModelTransformer($transformer);
 }
開發者ID:linestorm,項目名稱:tag-component-bundle,代碼行數:7,代碼來源:TagType.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     foreach ($options['variable']->getOptions() as $i => $option) {
         $builder->add(Urlizer::urlize($option->getName()), sprintf('sylius_%s_option_value_choice', $this->variableName), ['label' => $option->getPresentation(), 'option' => $option, 'property_path' => '[' . $i . ']']);
     }
     $builder->addModelTransformer(new VariantToCombinationTransformer($options['variable']));
 }
開發者ID:vikey89,項目名稱:Sylius,代碼行數:10,代碼來源:VariantMatchType.php

示例12: buildForm

 /**
  * Builds the form.
  *
  * This method is called after the extended type has built the form to
  * further modify it.
  *
  * @see FormTypeInterface::buildForm()
  *
  * @param FormBuilderInterface $builder The form builder
  * @param array $options The options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['encryption_profile'] === false) {
         return;
     }
     $builder->addModelTransformer(new EncryptTransformer($this->cipherTextGenerator, $options['encryption_profile']));
 }
開發者ID:SaveYa,項目名稱:Encryption,代碼行數:18,代碼來源:EncryptTypeExtension.php

示例13: buildForm

 /**
  * @param FormBuilderInterface $builder
  * @param array $options options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('site', TextType::class, ['constraints' => new Url()]);
     $builder->add('compare_sites', TextareaType::class, ['constraints' => new MultiUrl()]);
     $builder->add('save', SubmitType::class);
     $builder->addModelTransformer($this->transformer);
 }
開發者ID:morganus,項目名稱:Benchmarker,代碼行數:11,代碼來源:SitesType.php

示例14: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $transformer = new ProductToNumberTransformer($this->manager);
     $builder->addModelTransformer($transformer);
     //$builder
     //  ->add('product', 'EntityType::class', ['class'=>'AppBundle:product', 'property'=>'name']);
 }
開發者ID:DWS-DAW,項目名稱:T0,代碼行數:7,代碼來源:ProductSelectType.php

示例15: buildForm

 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $transformer = new ArrayKeyTransformer('content_id');
     $contentTransformer = new IdToEntityTransformer($this->contentManager);
     $builder->add($builder->create('content_id', 'hidden')->addModelTransformer($contentTransformer));
     $builder->addModelTransformer($transformer);
 }
開發者ID:NickyBeunder,項目名稱:ContentBundle,代碼行數:10,代碼來源:ContentPickerType.php


注:本文中的Symfony\Component\Form\FormBuilderInterface::addModelTransformer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。