本文整理汇总了PHP中Symfony\Component\Form\FormBuilder::addEventSubscriber方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::addEventSubscriber方法的具体用法?PHP FormBuilder::addEventSubscriber怎么用?PHP FormBuilder::addEventSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilder
的用法示例。
在下文中一共展示了FormBuilder::addEventSubscriber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
if ($options['allow_add'] && $options['prototype']) {
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array('label' => $options['prototype_name'] . 'label__'), $options['options']));
$builder->setAttribute('prototype', $prototype->getForm());
}
$resizeListener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']);
$builder->addEventSubscriber($resizeListener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']);
// Enable support for adders/removers unless "by_reference" is disabled
// (explicit calling of the setter is desired)
if ($options['by_reference']) {
$builder->addEventSubscriber(new MergeCollectionListener($options['allow_add'], $options['allow_delete'], MergeCollectionListener::MERGE_INTO_PARENT, $options['add_method'], $options['remove_method']));
}
}
示例2: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
if (null === $options['property_path']) {
$options['property_path'] = $builder->getName();
}
if (false === $options['property_path'] || '' === $options['property_path']) {
$options['property_path'] = null;
} else {
$options['property_path'] = new PropertyPath($options['property_path']);
}
$builder->setRequired($options['required'])
->setReadOnly($options['read_only'])
->setErrorBubbling($options['error_bubbling'])
->setEmptyData($options['empty_data'])
->setAttribute('by_reference', $options['by_reference'])
->setAttribute('property_path', $options['property_path'])
->setAttribute('error_mapping', $options['error_mapping'])
->setAttribute('max_length', $options['max_length'])
->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
->setData($options['data'])
->addValidator(new DefaultValidator());
if ($options['trim']) {
$builder->addEventSubscriber(new TrimListener());
}
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
$configs = array_replace($this->options, $options['configs']);
$sizeLimit = 2;
$fileDesc = '';
$fileExt = '';
$fileMeta = new Upload();
if (true === isset($configs['multi']) && $configs['multi']) {
$options['multiple'] = true;
}
if (true === $options['multiple']) {
$configs['multi'] = true;
}
if (!isset($options['sizeLimit'])) {
$max_upload = (int) ini_get('upload_max_filesize');
$sizeLimit = $max_upload * 1000000;
} else {
$sizeLimit = $options['sizeLimit'];
}
if (!isset($options['fileDesc'])) {
$fileDesc = 'Tous les fichiers';
} else {
$fileDesc = $options['fileDesc'];
}
if (!isset($options['fileExt'])) {
$fileExt = '*.*';
} else {
$fileExt = $options['fileExt'];
}
$builder->addEventSubscriber(new FileListener($this->rootDir, $options['multiple'], $this->em))->setAttribute('configs', $configs)->setAttribute('rootDir', $this->rootDir)->setAttribute('multiple', $options['multiple'])->setAttribute('session', $this->session)->setAttribute('fileDesc', $fileDesc)->setAttribute('fileExt', $fileExt)->setAttribute('sizeLimit', $sizeLimit)->setAttribute('fileMeta', $fileMeta);
}
示例4: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
if ($options['multiple']) {
$builder->addEventSubscriber(new MergeCollectionListener())->prependClientTransformer(new ModelsToArrayTransformer($options['choice_list']));
} else {
$builder->prependClientTransformer(new ModelToIdTransformer($options['choice_list']));
}
}
示例5: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
if ($options['allow_add'] && $options['prototype']) {
$builder->add('$$name$$', $options['type'], array_replace(array('property_path' => false, 'required' => false), $options['options']));
}
$listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']);
$builder->addEventSubscriber($listener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']);
}
示例6: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
if (!$options['choices'] && !$options['choice_list']) {
throw new FormException('Either the option "choices" or "choice_list" is required');
}
if ($options['choice_list'] && !$options['choice_list'] instanceof ChoiceListInterface) {
throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
}
if (!$options['choice_list']) {
$options['choice_list'] = new ArrayChoiceList($options['choices']);
}
if ($options['expanded']) {
// Load choices already if expanded
$options['choices'] = $options['choice_list']->getChoices();
foreach ($options['choices'] as $choice => $value) {
if ($options['multiple']) {
$builder->add((string)$choice, 'checkbox', array(
'value' => $choice,
'label' => $value,
// The user can check 0 or more checkboxes. If required
// is true, he is required to check all of them.
'required' => false,
));
} else {
$builder->add((string)$choice, 'radio', array(
'value' => $choice,
'label' => $value,
));
}
}
}
$builder->setAttribute('choice_list', $options['choice_list'])
->setAttribute('preferred_choices', $options['preferred_choices'])
->setAttribute('multiple', $options['multiple'])
->setAttribute('expanded', $options['expanded']);
if ($options['expanded']) {
if ($options['multiple']) {
$builder->appendClientTransformer(new ArrayToBooleanChoicesTransformer($options['choice_list']));
} else {
$builder->appendClientTransformer(new ScalarToBooleanChoicesTransformer($options['choice_list']));
$builder->addEventSubscriber(new FixRadioInputListener(), 10);
}
} else {
if ($options['multiple']) {
$builder->appendClientTransformer(new ArrayToChoicesTransformer());
} else {
$builder->appendClientTransformer(new ScalarToChoiceTransformer());
}
}
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
if ($options['allow_add'] && $options['prototype']) {
$prototype = $builder->create('$$' . $options['prototype_name'] . '$$', $options['type'], $options['options']);
$builder->setAttribute('prototype', $prototype->getForm());
}
$listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']);
$builder->addEventSubscriber($listener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']);
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
$configs = array_replace($this->options, $options['configs']);
if (isset($configs['multi']) && $configs['multi']) {
$options['multiple'] = true;
}
if ($options['multiple']) {
$configs['multi'] = true;
}
$builder->addEventSubscriber(new FileListener($this->rootDir, $options['multiple']))->setAttribute('configs', $configs)->setAttribute('rootDir', $this->rootDir)->setAttribute('multiple', $options['multiple']);
}
示例9: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('body');
$builder->add('is_published');
$builder->add('publish_to', 'date', array('widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
$builder->add('publish_from', 'date', array('widget' => 'single_text', 'format' => 'yyyy-MM-dd'));
$builder->add('author', 'extended_text', array('empty_value' => ''));
$builder->add('meta_description', 'extended_text', array('empty_value' => ''));
$builder->add('meta_keywords', 'extended_text', array('empty_value' => ''));
$builder->addEventSubscriber(new RemoveExtraDataListener());
}
示例10: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
$listener = new ResizeFormListener(
$builder->getFormFactory(),
$options['type'],
$options['type_options'],
$options['modifiable']
);
$builder->addEventSubscriber($listener);
}
示例11: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('fulltext', 'text');
$builder->add('text', 'text');
$builder->add('ident', 'text');
$builder->add('service', 'text');
$builder->add('number', 'text');
$builder->add('sender', 'text');
$builder->add('code', 'text');
$builder->add('date', 'text');
$builder->add('md5', 'text');
$builder->addEventSubscriber(new RemoveExtraDataListener());
}
示例12: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
if ($options['modifiable'] && $options['prototype']) {
$builder->add('$$name$$', $options['type'], array(
'property_path' => false,
'required' => false,
));
}
$listener = new ResizeFormListener($builder->getFormFactory(),
$options['type'], $options['modifiable']);
$builder->addEventSubscriber($listener);
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('address', 'field');
foreach (array('latitude', 'longitude', 'locality', 'country') as $field) {
$option = $options[$field];
if (isset($option['enabled']) && !empty($option['enabled'])) {
$type = 'field';
if (isset($option['hidden']) && !empty($option['hidden'])) {
$type = 'hidden';
}
$builder->add($field, $type);
}
}
$builder->addEventSubscriber(new GeolocationListener())->setAttribute('map', $options['map']);
}
示例14: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
if (null === $options['property_path']) {
$options['property_path'] = $builder->getName();
}
if (false === $options['property_path'] || '' === $options['property_path']) {
$options['property_path'] = null;
} else {
$options['property_path'] = new PropertyPath($options['property_path']);
}
if (!is_array($options['attr'])) {
throw new FormException('The "attr" option must be "array".');
}
$builder->setRequired($options['required'])->setDisabled($options['disabled'])->setErrorBubbling($options['error_bubbling'])->setEmptyData($options['empty_data'])->setAttribute('read_only', $options['read_only'])->setAttribute('by_reference', $options['by_reference'])->setAttribute('property_path', $options['property_path'])->setAttribute('error_mapping', $options['error_mapping'])->setAttribute('max_length', $options['max_length'])->setAttribute('pattern', $options['pattern'])->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))->setAttribute('attr', $options['attr'] ?: array())->setAttribute('invalid_message', $options['invalid_message'])->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])->setAttribute('translation_domain', $options['translation_domain'])->setAttribute('virtual', $options['virtual'])->setData($options['data'])->setDataMapper(new PropertyPathMapper($options['data_class']))->addEventSubscriber(new ValidationListener());
if ($options['trim']) {
$builder->addEventSubscriber(new TrimListener());
}
}
示例15: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('id', 'hidden');
$builder->add('amount', 'hidden');
$builder->add('description', 'hidden');
$builder->add('url', 'hidden');
$builder->add('urlc', 'hidden');
$builder->add('type', 'hidden');
$builder->add('buttontext', 'hidden');
$builder->add('control', 'hidden');
$builder->add('firstname', 'hidden');
$builder->add('lastname', 'hidden');
$builder->add('email', 'hidden');
$builder->add('street', 'hidden');
$builder->add('streetn1', 'hidden');
$builder->add('streetn2', 'hidden');
$builder->add('city', 'hidden');
$builder->add('code', 'hidden');
$builder->addEventSubscriber(new RemoveExtraDataListener());
}