Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rande committed Oct 16, 2014
1 parent 7f4da51 commit 201375d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Form/Extension/Field/Type/FormTypeFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
/**
* We have a child, so we need to upgrade block prefix
*/
if ($view->parent->vars['sonata_admin_enabled'] && !$sonataAdmin['admin']) {
if ($view->parent && $view->parent->vars['sonata_admin_enabled'] && !$sonataAdmin['admin']) {
$blockPrefixes = $view->vars['block_prefixes'];

$baseName = str_replace('.', '_', $view->parent->vars['sonata_admin_code']);
Expand Down
19 changes: 19 additions & 0 deletions Tests/Form/Extension/Field/Type/FormTypeFieldExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ public function testbuildViewWithNestedForm()
$this->assertEquals($expected, $formView->vars['block_prefixes']);
$this->assertTrue($formView->vars['sonata_admin_enabled']);
}

public function testbuildViewWithNestedFormWithNoParent()
{
$eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');

$formView = new FormView();
$options = array();
$config = new FormConfigBuilder('test', 'stdClass', $eventDispatcher, $options);
$form = new Form($config);

$extension = new FormTypeFieldExtension();
$extension->buildView($formView, $form, array(
'sonata_help' => 'help text'
));

$this->assertArrayNotHasKey('block_prefixes', $formView->vars);
$this->assertArrayHasKey('sonata_admin_enabled', $formView->vars);
$this->assertArrayHasKey('sonata_admin', $formView->vars);
}
}

0 comments on commit 201375d

Please sign in to comment.