本文整理汇总了PHP中Symfony\Component\Form\Form::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::add方法的具体用法?PHP Form::add怎么用?PHP Form::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addField
protected function addField(Form $form, $municipio)
{
$formOptions = array('class' => 'SiSuCuentaBundle:Parroquia', 'empty_value' => '-- Seleccionar --', 'attr' => array('class' => 'usuario_parroquia'), 'required' => true, 'label' => 'Parroquia', 'query_builder' => function (EntityRepository $er) use($municipio) {
return $er->createQueryBuilder('parroquia')->where('parroquia.municipio = :municipio')->setParameter('municipio', $municipio);
});
$form->add('parroquia', 'entity', $formOptions);
}
示例2: createLoginForm
private function createLoginForm($operator = null)
{
$form = new Form('login', array('validator' => $this->get('validator')));
$form->add(new TextField('email'));
$form->add(new PasswordField('passwd'));
return $form;
}
示例3: managePlural
/**
* @param TranslatableLabel $label
* @param Form $form
*/
protected function managePlural($label, $message, $form, $locale)
{
$labelManager = $this->labelManager;
$explicitRules = array();
$standardRules = array();
$labelManager->getPluralForms($message, $standardRules, $explicitRules);
for ($i = 0; $i < max(2, count($standardRules)); $i++) {
$form->add(self::PLURAL_FIELD_PREFIX . $i, $labelManager->getValueFieldType($label), array('required' => false, 'label' => sprintf('bigfoot_core.translatable_label.plural.standard_%s', $i), 'data' => isset($standardRules[$i]) ? $standardRules[$i] : '', 'mapped' => false, 'attr' => array('data-locale' => $locale)));
}
foreach ($explicitRules as $interval => $value) {
$form->add(self::PLURAL_FIELD_PREFIX . $labelManager->transformInterval($interval), $labelManager->getValueFieldType($label), array('required' => false, 'label' => $this->translator->trans('bigfoot_core.translatable_label.plural.explicit', array('%interval%' => $interval)), 'data' => $value, 'mapped' => false, 'attr' => array('data-locale' => $locale)));
}
}
示例4: add
/**
* {@inheritDoc}
*
* @throws FormException When the field is in mode HybridField::FIELD adding
* subfields is not allowed
*/
public function add($field)
{
if ($this->mode === self::FIELD) {
throw new FormException('You cannot add nested fields while in mode FIELD');
}
return parent::add($field);
}
示例5: testCollectSubmittedDataExpandedFormsErrors
public function testCollectSubmittedDataExpandedFormsErrors()
{
$child1Form = $this->createForm('child1');
$child11Form = $this->createForm('child11');
$child2Form = $this->createForm('child2');
$child21Form = $this->createForm('child21');
$child1Form->add($child11Form);
$child2Form->add($child21Form);
$this->form->add($child1Form);
$this->form->add($child2Form);
$this->dataExtractor->method('extractConfiguration')->will($this->returnValue(array()));
$this->dataExtractor->method('extractDefaultData')->will($this->returnValue(array()));
$this->dataExtractor->expects($this->at(10))->method('extractSubmittedData')->with($this->form)->will($this->returnValue(array('errors' => array())));
$this->dataExtractor->expects($this->at(11))->method('extractSubmittedData')->with($child1Form)->will($this->returnValue(array('errors' => array())));
$this->dataExtractor->expects($this->at(12))->method('extractSubmittedData')->with($child11Form)->will($this->returnValue(array('errors' => array('foo'))));
$this->dataExtractor->expects($this->at(13))->method('extractSubmittedData')->with($child2Form)->will($this->returnValue(array('errors' => array())));
$this->dataExtractor->expects($this->at(14))->method('extractSubmittedData')->with($child21Form)->will($this->returnValue(array('errors' => array())));
$this->dataCollector->collectSubmittedData($this->form);
$this->dataCollector->buildPreliminaryFormTree($this->form);
$data = $this->dataCollector->getData();
$formData = $data['forms']['name'];
$child1Data = $formData['children']['child1'];
$child11Data = $child1Data['children']['child11'];
$child2Data = $formData['children']['child2'];
$child21Data = $child2Data['children']['child21'];
$this->assertTrue($formData['has_children_error']);
$this->assertTrue($child1Data['has_children_error']);
$this->assertFalse(isset($child11Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
$this->assertFalse($child2Data['has_children_error']);
$this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
}
示例6: appendToForm
/**
* @param FormBuilder|Form $builder
*/
public function appendToForm(&$builder, $data, $formArea)
{
if ($formArea == 'features') {
$name = strtolower($this->getName());
if ($this->factory->serviceExists('mautic.form.type.social.' . $name)) {
$builder->add('shareButton', 'socialmedia_' . $name, array('label' => 'mautic.integration.form.sharebutton', 'required' => false, 'data' => isset($data['shareButton']) ? $data['shareButton'] : array()));
}
}
}
示例7: addFields
protected function addFields(Form $form)
{
foreach ($this->elementsFrom as $element) {
$options = $this->createOptionsFor($element);
$name = $this->encodeFieldname($options['label']);
$form->add($name, $this->attributes['type'], $options);
}
return $form;
}
示例8: addField
protected function addField(Form $form, $estado)
{
// actualizamos el campo municipio, pasandole el estado a la opción
// query_builder, para que el dql tome en cuenta el estado
// y filtre la consulta por su valor.
$formOptions = array('class' => 'SiSuCuentaBundle:Municipio', 'empty_value' => '-- Seleccionar --', 'attr' => array('class' => 'usuario_municipio'), 'required' => true, 'label' => 'Municipio', 'query_builder' => function (EntityRepository $er) use($estado) {
return $er->createQueryBuilder('municipio')->where('municipio.estado = :estado')->setParameter('estado', $estado);
});
$form->add('municipio', 'entity', $formOptions);
}
示例9: testFinalFormReliesOnFormViewStructure
public function testFinalFormReliesOnFormViewStructure()
{
$this->form->add($this->createForm('first'));
$this->form->add($this->createForm('second'));
$this->view->children['second'] = $this->childView;
$this->dataCollector->buildPreliminaryFormTree($this->form);
$this->assertSame(array('forms' => array('name' => array('children' => array('first' => array('children' => array()), 'second' => array('children' => array())))), 'nb_errors' => 0), $this->dataCollector->getData());
$this->dataCollector->buildFinalFormTree($this->form, $this->view);
$this->assertSame(array('forms' => array('name' => array('children' => array('second' => array('children' => array())))), 'nb_errors' => 0), $this->dataCollector->getData());
}
示例10: _addFieldToSymfonyForm
/**
* Add a field (in form of an array) to $_form
* Sets the required option to what is defined in the validator.
*
* @param array $fieldArray Array consisting of child, type and options(inc. label) for the field
*
* @return Handler Returns $this for chainability
*/
protected function _addFieldToSymfonyForm(&$fieldArray)
{
$validatorField = $this->getValidator()->getField($this->_getChildName($fieldArray['child']));
$fieldArray['options']['required'] = !$validatorField->optional;
if ($this->_repeatable) {
$this->_addCollection($fieldArray['child'], $fieldArray['type'], $fieldArray['options']);
} else {
$this->_form->add($fieldArray['child'], $fieldArray['type'], $fieldArray['options']);
}
}
示例11: __construct
public function __construct(Form $form, Request $request, UserManagerInterface $userManager)
{
// borrando campos no necesarios
$form->remove('gender');
$form->remove('website');
$form->remove('biography');
$form->remove('timezone');
$form->remove('phone');
$form->remove('locale');
$form->remove('dateOfBirth');
// cargando nuevos campos
$form->add('username', null, array('label' => 'Name of User'));
$form->add('email');
$form->add('organization');
// $form->add('gravatar', 'file', array(
// 'mapped' => false,
// 'attr' => ['class' => 'filestyle','data-buttonBefore'=> 'true', 'data-buttonText' => 'Choose file' ]
// ));
parent::__construct($form, $request, $userManager);
}
示例12: buildTypeSettingsForm
/**
* @param Form $form Main form.
* @param string $providerName Provider.
*/
protected function buildTypeSettingsForm(Form $form, $providerName)
{
// create sub-form wrapper
$subForm = $form->getConfig()->getFormFactory()->createNamed('properties', 'form', null, array('label' => false, 'auto_initialize' => false));
//Add provider form
if ($providerName && isset($this->providers[$providerName])) {
$provider = $this->providers[$providerName];
// delegate form structure building for specific provider
$provider->buildForm($subForm);
}
$form->add($subForm);
}
示例13: addField
public function addField(Form $form, $parser = null)
{
if ($parser === null) {
return false;
}
$options = $form->getConfig()->getOptions();
$em = $options['em'];
if (!$parser instanceof Newscoop\IngestPluginBundle\Entity\Parser) {
$parser = $em->getRepository('Newscoop\\IngestPluginBundle\\Entity\\Parser')->findOneById($parser);
}
if ($parser->requiresUrl()) {
$form->add('url', 'url', array('label' => 'plugin.ingest.feeds.url', 'required' => true));
}
}
示例14: testRemoveFields
public function testRemoveFields()
{
$dataMapper = $this->getMock('Symfony\\Component\\Form\\DataMapperInterface');
$config = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
$config->expects($this->any())->method('getName')->will($this->returnValue('root'));
$config->expects($this->any())->method('getCompound')->will($this->returnValue(true));
$config->expects($this->any())->method('getDataMapper')->will($this->returnValue($dataMapper));
$form = new Form($config);
$config = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
$config->expects($this->any())->method('getName')->will($this->returnValue('child'));
$form->add(new Form($config));
FormHelper::removeFields(array(), $form);
$this->assertFalse(isset($form['child']));
}
示例15: appendToForm
/**
* @param FormBuilder|Form $builder
*/
public function appendToForm(&$builder, $data, $formArea)
{
if ($formArea == 'features' || $formArea == 'integration') {
if ($this->isAuthorized()) {
$name = strtolower($this->getName());
if ($this->factory->serviceExists('mautic.form.type.emailmarketing.' . $name)) {
if ($formArea == 'integration' && isset($data['leadFields']) && empty($data['list_settings']['leadFields'])) {
$data['list_settings']['leadFields'] = $data['leadFields'];
}
$builder->add('list_settings', 'emailmarketing_' . $name, array('label' => false, 'form_area' => $formArea, 'data' => isset($data['list_settings']) ? $data['list_settings'] : array()));
}
}
}
}