本文整理汇总了PHP中Symfony\Component\Form\FormConfigBuilder::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP FormConfigBuilder::setAttribute方法的具体用法?PHP FormConfigBuilder::setAttribute怎么用?PHP FormConfigBuilder::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormConfigBuilder
的用法示例。
在下文中一共展示了FormConfigBuilder::setAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testbuildViewWithWithSonataAdmin
public function testbuildViewWithWithSonataAdmin()
{
$admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin->expects($this->once())->method('getCode')->will($this->returnValue('my.admin.reference'));
$eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$formView = new FormView();
$options = array();
$config = new FormConfigBuilder('test', 'stdClass', $eventDispatcher, $options);
$config->setAttribute('sonata_admin', array('admin' => $admin, 'name' => 'name'));
$config->setAttribute('sonata_admin_enabled', true);
$form = new Form($config);
$formView->vars['block_prefixes'] = array('form', 'field', 'text', '_s50b26aa76cb96_username');
$extension = new FormTypeFieldExtension();
$extension->buildView($formView, $form, array());
$this->assertArrayHasKey('block_prefixes', $formView->vars);
$this->assertArrayHasKey('sonata_admin_enabled', $formView->vars);
$this->assertArrayHasKey('sonata_admin', $formView->vars);
$expected = array('form', 'field', 'text', 'my_admin_reference_text', 'my_admin_reference_name_text', 'my_admin_reference_name_text_username');
$this->assertEquals($expected, $formView->vars['block_prefixes']);
$this->assertTrue($formView->vars['sonata_admin_enabled']);
}
示例2: testbuildViewWithNestedForm
public function testbuildViewWithNestedForm()
{
$eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$formView = new FormView();
$formView->vars['name'] = 'format';
$options = array();
$config = new FormConfigBuilder('test', 'stdClass', $eventDispatcher, $options);
$config->setAttribute('sonata_admin', array('admin' => false));
$form = new Form($config);
$formView->parent = new FormView();
$formView->parent->vars['sonata_admin_enabled'] = true;
$formView->parent->vars['sonata_admin_code'] = 'parent_code';
$formView->parent->vars['name'] = 'settings';
$formView->vars['block_prefixes'] = array('form', 'field', 'text', '_s50b26aa76cb96_settings_format');
$extension = new FormTypeFieldExtension(array(), array());
$extension->buildView($formView, $form, array('sonata_help' => 'help text'));
$this->assertArrayHasKey('block_prefixes', $formView->vars);
$this->assertArrayHasKey('sonata_admin_enabled', $formView->vars);
$this->assertArrayHasKey('sonata_admin', $formView->vars);
$expected = array('value' => null, 'attr' => array(), 'name' => 'format', 'block_prefixes' => array('form', 'field', 'text', 'parent_code_text', 'parent_code_text_settings_format', 'parent_code_text_settings_settings_format'), 'sonata_admin_enabled' => true, 'sonata_admin' => array('admin' => false, 'field_description' => false, 'name' => false, 'edit' => 'standard', 'inline' => 'natural', 'block_name' => false, 'class' => false, 'options' => array()), 'sonata_admin_code' => 'parent_code');
$this->assertEquals($expected, $formView->vars);
}