本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::setData方法的具体用法?PHP FormBuilderInterface::setData怎么用?PHP FormBuilderInterface::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', HiddenType::class);
$builder->add('type', HiddenType::class);
$builder->add('value', TextType::class, array('label' => false));
$builder->setData($this->setting);
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$configModel = $options['config_model'];
$data = array();
if ($configModel instanceof FieldConfigModel) {
$className = $configModel->getEntity()->getClassName();
$fieldName = $configModel->getFieldName();
$fieldType = $configModel->getType();
$configType = PropertyConfigContainer::TYPE_FIELD;
/**
* Add read only field name and field type
*/
$builder->add('fieldName', 'text', array('label' => 'oro.entity_config.form.name.label', 'block' => 'general', 'disabled' => true, 'data' => $fieldName));
$builder->add('type', 'choice', array('label' => 'oro.entity_config.form.type.label', 'choices' => [], 'block' => 'general', 'disabled' => true, 'empty_value' => 'oro.entity_extend.form.data_type.' . $fieldType));
} else {
$className = $configModel->getClassName();
$fieldName = null;
$fieldType = null;
$configType = PropertyConfigContainer::TYPE_ENTITY;
}
foreach ($this->configManager->getProviders() as $provider) {
if ($provider->getPropertyConfig()->hasForm($configType, $fieldType)) {
$config = $this->configManager->getConfig($provider->getId($className, $fieldName, $fieldType));
$builder->add($provider->getScope(), new ConfigScopeType($provider->getPropertyConfig()->getFormItems($configType, $fieldType), $config, $this->configManager, $configModel), array('block_config' => $this->getFormBlockConfig($provider, $configType)));
$data[$provider->getScope()] = $config->all();
}
}
$builder->setData($data);
$builder->addEventSubscriber(new ConfigSubscriber($this->doctrine, $this->configManager, $this->translator, $this->dbTranslationMetadataCache));
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$configModel = $options['config_model'];
$data = array();
if ($configModel instanceof FieldConfigModel) {
$className = $configModel->getEntity()->getClassName();
$fieldName = $configModel->getFieldName();
$fieldType = $configModel->getType();
$configType = PropertyConfigContainer::TYPE_FIELD;
} else {
$className = $configModel->getClassName();
$fieldName = null;
$fieldType = null;
$configType = PropertyConfigContainer::TYPE_ENTITY;
}
foreach ($this->configManager->getProviders() as $provider) {
if ($provider->getPropertyConfig()->hasForm($configType, $fieldType)) {
$config = $provider->getConfig($className, $fieldName);
$builder->add($provider->getScope(), new ConfigScopeType($provider->getPropertyConfig()->getFormItems($configType, $fieldType), $config, $this->configManager, $configModel), array('block_config' => (array) $provider->getPropertyConfig()->getFormBlockConfig($configType)));
$data[$provider->getScope()] = $config->all();
}
}
if ($fieldType == 'optionSet') {
$data['extend']['set_options'] = $this->configManager->getEntityManager()->getRepository(OptionSet::ENTITY_NAME)->findOptionsByField($configModel->getId());
}
$builder->setData($data);
$builder->addEventSubscriber(new ConfigSubscriber($this->configManager));
}
示例4: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$admin = clone $this->getAdmin($options);
if ($admin->hasParentFieldDescription()) {
$admin->getParentFieldDescription()->setAssociationAdmin($admin);
}
if ($options['delete'] && $admin->isGranted('DELETE')) {
if (!array_key_exists('translation_domain', $options['delete_options']['type_options'])) {
$options['delete_options']['type_options']['translation_domain'] = $admin->getTranslationDomain();
}
$builder->add('_delete', $options['delete_options']['type'], $options['delete_options']['type_options']);
}
// hack to make sure the subject is correctly set
// https://github.com/sonata-project/SonataAdminBundle/pull/2076
if ($builder->getData() === null) {
$p = new PropertyAccessor(false, true);
try {
$subject = $p->getValue($admin->getParentFieldDescription()->getAdmin()->getSubject(), $this->getFieldDescription($options)->getFieldName() . $options['property_path']);
$builder->setData($subject);
} catch (NoSuchIndexException $e) {
// no object here
}
}
$admin->setSubject($builder->getData());
$admin->defineFormBuilder($builder);
$builder->addModelTransformer(new ArrayToModelTransformer($admin->getModelManager(), $admin->getClass()));
}
示例5: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (array_key_exists('property_path', $options) && is_null($options['property_path'])) {
$builder->setData($options['prototype_data']());
}
$builder->add('fieldId', 'text', array('label' => 'open_orchestra_backoffice.form.field_type.field_id', 'attr' => array('help_text' => 'open_orchestra_backoffice.form.allowed_characters.helper')))->add('labels', 'oo_multi_languages', array('label' => 'open_orchestra_backoffice.form.field_type.labels', 'languages' => $this->backOfficeLanguages))->add('type', 'choice', array('choices' => $this->getChoicesType(), 'label' => 'open_orchestra_backoffice.form.field_type.type', 'attr' => array('class' => 'content_type_change_type')))->add('listable', 'checkbox', array('label' => 'open_orchestra_backoffice.form.field_type.listable', 'required' => false))->add('translatable', 'checkbox', array('label' => 'open_orchestra_backoffice.form.field_type.translatable', 'required' => false))->add('searchable', 'checkbox', array('label' => 'open_orchestra_backoffice.form.field_type.searchable', 'required' => false))->add('orderable', 'checkbox', array('label' => 'open_orchestra_backoffice.form.field_type.orderable', 'required' => false))->add('orderDirection', 'choice', array('choices' => $this->getChoicesOrder(), 'label' => 'open_orchestra_backoffice.form.field_type.orderDirection', 'required' => false))->add('position', 'integer', array('label' => 'open_orchestra_backoffice.form.field_type.position', 'required' => false, 'attr' => array('class' => 'oo-field-position')));
$builder->addEventSubscriber(new FieldTypeTypeSubscriber($this->fieldOptions, $this->fieldOptionClass, $this->fieldTypeClass, $this->fieldTypeParameters));
}
示例6: setDefaultValue
/**
* @param FormBuilderInterface $builder
* @param $property
* @param $value
*
* @return $this
*/
public function setDefaultValue(FormBuilderInterface &$builder, $property, $value)
{
$data = $builder->getData();
if ($this->isEmpty($this->accessor->getValue($data, $property))) {
$this->accessor->setValue($data, $property, $value);
$builder->setData($data);
}
return $this;
}
示例7: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = array();
foreach ($this->locales as $locale => $label) {
$builder->add($locale, 'textarea', array('label' => $label, 'required' => false));
$data[$locale] = (string) $this->message->getLocaleTranslation($locale);
}
$builder->setData($data);
}
示例8: buildForm
/**
* @param FormBuilderInterface $builder The form builder
*/
public function buildForm(FormBuilderInterface $builder)
{
$data = $builder->getData();
foreach ($this->types as $name => $type) {
$builder->add($name, $type);
$data[$name] = $this->data[$name];
}
$builder->setData($data);
}
示例9: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Unlike in other types, where the data is NULL by default, it
// needs to be a Boolean here. setData(null) is not acceptable
// for checkboxes and radio buttons (unless a custom model
// transformer handles this case).
// We cannot solve this case via overriding the "data" option, because
// doing so also calls setDataLocked(true).
$builder->setData(isset($options['data']) ? $options['data'] : false);
$builder->addViewTransformer(new BooleanToStringTransformer($options['value']));
}
示例10: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*
* @todo Set 'required' attribute on all elements at once (e.g. in a cycle).
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$role_alias = 'r';
$role_field_name = $options['role_field_name'];
$builder->add('firstName', 'text', array('required' => false))->add('secondName', 'text', array('required' => false))->add('patronymic', 'text', array('required' => false))->add('callsign', 'text', array('required' => false))->add('balance', 'money', array('required' => false, 'currency' => 'RUB', 'grouping' => true))->add('homeAddress', 'text', array('required' => false))->add('privatePhones', 'text', array('required' => false))->add('workPhones', 'text', array('required' => false))->add('email', 'email', array('required' => false))->add('birthdate', 'filter_date_range', array('required' => false))->add('roles', 'filter_entity', array('required' => false, 'choices' => isset($options['employe_roles']) ? $options['employe_roles'] : null, 'class' => 'TaxiPrizeTaxiBundle:EmployeRole', 'property' => 'readable_name', 'multiple' => true, 'expanded' => false, 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) use($role_alias, $role_field_name) {
$qb = $filterQuery->getQueryBuilder();
$roles = $values['value']->toArray();
if (!empty($roles)) {
$qb->andWhere('cr.role IN (:roles)');
$qb->setParameter('roles', $roles);
}
}));
$builder->setData(array('roles' => array()));
// foreach ($builder->all() as $elem)
// $elem->setAttribute('required', false);
}
示例11: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Survey $survey */
$survey = $options['survey'];
$user = $this->tokenStorage->getToken()->getUser();
$questions = $builder->create('q', null, array('required' => true, 'mapped' => false, 'compound' => true, 'label' => false, 'error_bubbling' => true));
foreach ($survey->getQuestions() as $question) {
$question->getField()->buildForm($questions, array('mapped' => false));
}
$builder->add($questions);
$result = new SurveyResult();
if ($survey->isEditAllowed()) {
$savedResult = $this->manager->getRepository('SurveyBundle:SurveyResult')->findOneBy(array('author' => $user, 'survey' => $survey));
$result = $savedResult ?: $result;
}
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use($survey, $user) {
$form = $event->getForm();
/** @var SurveyResult $result */
$result = $event->getData();
$result->setSurvey($survey);
if ($user instanceof UserInterface) {
$result->setAuthor($user);
}
$result->sanitize();
foreach ($result->getAnswers() as $answer) {
$form->get('q')->get($answer->getValue()->getField()->getName())->setData($answer->getValue());
}
});
$builder->setData($result);
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($survey, $user) {
$form = $event->getForm();
/** @var SurveyResult $result */
$result = $event->getData();
$result->setSurvey($survey);
if ($user instanceof UserInterface) {
$result->setAuthor($user);
}
$result->setTimeUpdated(new \DateTime());
foreach ($form->get('q')->all() as $key => $value) {
if (!$value->getData()) {
continue;
}
$answer = new SurveyAnswer($value->getData());
$result->addAnswer($answer);
}
});
}
示例12: adaptForm
/**
* Modify the form with the fields of the current page part
*
* @param FormBuilderInterface $formBuilder The form builder
* @param ArrayObject $fields The fields
* @param int $sequence The sequence of the form field
*/
public function adaptForm(FormBuilderInterface $formBuilder, ArrayObject $fields, $sequence)
{
$ffsf = new FileFormSubmissionField();
$ffsf->setFieldName("field_" . $this->getUniqueId());
$ffsf->setLabel($this->getLabel());
$ffsf->setSequence($sequence);
$data = $formBuilder->getData();
$data['formwidget_' . $this->getUniqueId()] = $ffsf;
$constraints = array();
if ($this->getRequired()) {
$options = array();
if (!empty($this->errorMessageRequired)) {
$options['message'] = $this->errorMessageRequired;
}
$constraints[] = new NotBlank($options);
}
$formBuilder->add('formwidget_' . $this->getUniqueId(), new FileFormSubmissionType(), array('label' => $this->getLabel(), 'constraints' => $constraints, 'required' => $this->getRequired()));
$formBuilder->setData($data);
$fields[] = $ffsf;
}
示例13: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!isset($options['default'])) {
if ($options['required']) {
$dateRange = new DateRange($this->date_format);
$dateRange->createToDate(new \DateTime(), $this->default_interval);
} else {
$dateRange = null;
}
} else {
$dateRange = $options['default'];
}
$options['default'] = $dateRange;
$builder->appendClientTransformer(new DateRangeToValueTransformer($this->date_format));
$builder->setData($options['default']);
// Datepicker date format
$searches = array('d', 'm', 'y', 'Y');
$replaces = array('dd', 'mm', 'yy', 'yyyy');
$datepicker_format = str_replace($searches, $replaces, $this->date_format);
$builder->setAttribute('datepicker_date_format', $datepicker_format);
}
示例14: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$admin = clone $this->getAdmin($options);
if ($admin->hasParentFieldDescription()) {
$admin->getParentFieldDescription()->setAssociationAdmin($admin);
}
if ($options['delete'] && $admin->isGranted('DELETE')) {
if (!array_key_exists('translation_domain', $options['delete_options']['type_options'])) {
$options['delete_options']['type_options']['translation_domain'] = $admin->getTranslationDomain();
}
$builder->add('_delete', $options['delete_options']['type'], $options['delete_options']['type_options']);
}
// hack to make sure the subject is correctly set
// https://github.com/sonata-project/SonataAdminBundle/pull/2076
if ($builder->getData() === null) {
$p = new PropertyAccessor(false, true);
try {
$parentSubject = $admin->getParentFieldDescription()->getAdmin()->getSubject();
if ($parentSubject !== null && $parentSubject !== false) {
// for PropertyAccessor < 2.5
// @todo remove this code for old PropertyAccessor after dropping support for Symfony 2.3
if (!method_exists($p, 'isReadable')) {
$subjectCollection = $p->getValue($parentSubject, $this->getFieldDescription($options)->getFieldName());
if ($subjectCollection instanceof Collection) {
$subject = $subjectCollection->get(trim($options['property_path'], '[]'));
}
} else {
// for PropertyAccessor >= 2.5
$subject = $p->getValue($parentSubject, $this->getFieldDescription($options)->getFieldName() . $options['property_path']);
}
$builder->setData($subject);
}
} catch (NoSuchIndexException $e) {
// no object here
}
}
$admin->setSubject($builder->getData());
$admin->defineFormBuilder($builder);
$builder->addModelTransformer(new ArrayToModelTransformer($admin->getModelManager(), $admin->getClass()));
}
示例15: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
// hidden input to store ids of edited messages
$builder->add('ids', 'hidden');
$data = array();
$qb = $this->em->createQueryBuilder();
$qb->select('m.id, m.parameters, m.identification, t.locale, t.content')->from('AOTranslationBundle:Message', 'm')->leftJoin('m.translations', 't')->join('m.domain', 'd')->where('m.identification IN (:ids) AND d.name=:domain')->orderBy('m.identification');
$q = $qb->getQuery();
foreach ($this->messages as $domain => $messages) {
$q->setParameter('ids', $messages);
$q->setParameter('domain', $domain);
// store additional infos for displaying in translations table
$infos = array();
foreach ($q->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY) as $row) {
$infos[$row['id']] = array('id' => $row['id'], 'identification' => $row['identification'], 'parameters' => $row['parameters']);
// embed message form row
$builder->add((string) $row['id'], new MessageType($this->locales));
// set default value
$data[$row['id']][$row['locale']] = $row['content'];
}
$this->messages[$domain] = $infos;
}
$builder->setData($data);
}