本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::getType方法的具体用法?PHP FormBuilderInterface::getType怎么用?PHP FormBuilderInterface::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::getType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* Adds a CSRF field to the form when the CSRF protection is enabled.
*
* @param FormBuilderInterface $builder The form builder
* @param array $options The options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['csrf_protection']) {
return;
}
$builder->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_token_manager'], $options['csrf_token_id'] ?: ($builder->getName() ?: get_class($builder->getType()->getInnerType())), $options['csrf_message'], $this->translator, $this->translationDomain));
}
示例2: buildForm
/**
* Adds a CSRF field to the form when the CSRF protection is enabled.
*
* @param FormBuilderInterface $builder The form builder
* @param array $options The options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['csrf_protection']) {
return;
}
$builder->setAttribute('csrf_factory', $builder->getFormFactory())->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_provider'], $options['intention'] ?: ($builder->getName() ?: get_class($builder->getType()->getInnerType()))));
}
示例3: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Creatd with createNamed('', ...) so likely an API request, might
// need to make this a little better in the future
$buildTabs = $builder->getName() === '' ? false : $options['build_tabs'];
$tabsData = $options['tabs_data'];
$formType = $builder->getType()->getInnerType();
$tabDefaults = ['inherit_data' => true];
foreach ($tabsData as $name => $data) {
$tabOptions = array_merge($tabDefaults, $data);
$forceTab = isset($data['force_tab']) ? $data['force_tab'] : false;
// Remove unused option
if ($forceTab) {
unset($tabOptions['force_tab']);
}
// Build Tab
if ($buildTabs || $forceTab) {
$parent = $builder->create($name, 'tab', $tabOptions);
$builder->add($parent);
// Just add it to the main form
} else {
$parent = $builder;
}
// Get method name
$method = sprintf('build%sForm', ucfirst($name));
if (!method_exists($formType, $method)) {
throw new \InvalidArgumentException(sprintf('Method "%s" does not exist in "%s"', $method, get_class($formType)));
}
// call buildTabNameForm
call_user_func([$formType, $method], $parent, $options, $builder->getData());
}
}
示例4: getTypes
/**
* @param \Symfony\Component\Form\FormBuilderInterface $formBuilder
*
* @return array
*/
protected function getTypes(FormBuilderInterface $formBuilder)
{
$types = array();
for ($type = $formBuilder->getType(); null !== $type; $type = $type->getParent()) {
array_unshift($types, $type->getInnerType());
}
return $types;
}
示例5: assertFormType
/**
* Assert that the form element has an inner type of type $typeClass and
* the specified options with their values.
*
* @param FormBuilderInterface $element
* @param string $typeClass FQN class
* @param array $options keys are option names, values the
* expected option values
*/
private function assertFormType(FormBuilderInterface $element, $typeClass, array $options)
{
$type = $element->getType()->getInnerType();
$this->assertInstanceOf($typeClass, $type);
foreach ($options as $option => $expected) {
$this->assertEquals($expected, $element->getOption($option), "Option '{$option}' does not have the expected value '" . serialize($expected) . "'");
}
}