diff --git a/Admin/BlockAdmin.php b/Admin/BlockAdmin.php index 72a5ad7..bd4ac53 100644 --- a/Admin/BlockAdmin.php +++ b/Admin/BlockAdmin.php @@ -255,9 +255,7 @@ public function getPersistentParameters() $parameters['composer'] = $composer; } - if ($composer = $this->getRequest()->get('type')) { - $parameters['type'] = $composer; - } + $parameters['type'] = $this->getRequest()->get('type'); return $parameters; } @@ -401,6 +399,14 @@ protected function configureFormFields(FormMapper $formMapper) */ public function toString($object) { - return $object->getName(); + if (!is_object($object)) { + return ''; + } + + if (method_exists($object, 'getName') && null !== $object->getName()) { + return (string) $object->getName(); + } + + return parent::toString($object); } } diff --git a/Tests/Admin/BlockAdminTest.php b/Tests/Admin/BlockAdminTest.php new file mode 100644 index 0000000..7a34e2a --- /dev/null +++ b/Tests/Admin/BlockAdminTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\DashboardBundle\Tests\Admin; + +use Sonata\AdminBundle\Admin\Admin; +use Sonata\DashboardBundle\Admin\BlockAdmin; +use Sonata\DashboardBundle\Tests\Fixtures\Entity\FooGetName; +use Sonata\DashboardBundle\Tests\Fixtures\Entity\FooGetNameNull; +use Sonata\DashboardBundle\Tests\Fixtures\Entity\FooNoGetName; + +/** + * BlockAdminTest. + * + * @author Stéphane Paté + */ +class BlockAdminTest extends \PHPUnit_Framework_TestCase +{ + public function testToString() + { + $admin = new BlockAdmin( + 'sonata.dashboard.admin.block', + 'DashboardBundle\Entity\BaseBlock', + 'SonataDashboardBundle:BlockAdmin' + ); + + $s = new FooGetName(); + $this->assertSame('GetName', $admin->toString($s)); + + $s = new FooGetNameNull(); + $this->assertSame('GetNameNull', $admin->toString($s)); + + $s = new FooNoGetName(); + $this->assertSame('NoGetName', $admin->toString($s)); + } +} diff --git a/Tests/Fixtures/Entity/FooGetName.php b/Tests/Fixtures/Entity/FooGetName.php new file mode 100644 index 0000000..62c10d3 --- /dev/null +++ b/Tests/Fixtures/Entity/FooGetName.php @@ -0,0 +1,11 @@ +