当前位置: 首页>>代码示例>>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;未经允许,请勿转载。