From 3b9c7526a338bbb77bab980ac124e9deefebb2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Sat, 29 Nov 2014 19:03:21 +0100 Subject: [PATCH] Added support for bundles without a vendor name e.g. AppBundle from Symfony best practices --- Admin/Admin.php | 11 +++++------ Tests/Admin/AdminTest.php | 14 +++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Admin/Admin.php b/Admin/Admin.php index 3b8755de83..6af0215325 100644 --- a/Admin/Admin.php +++ b/Admin/Admin.php @@ -55,7 +55,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface const CONTEXT_MENU = 'menu'; const CONTEXT_DASHBOARD = 'dashboard'; - const CLASS_REGEX = '@([A-Za-z0-9]*)\\\(Bundle\\\)?([A-Za-z0-9]+)Bundle\\\(Entity|Document|Model|PHPCR|CouchDocument|Phpcr|Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB)\\\(.*)@'; + const CLASS_REGEX = '@(?:([A-Za-z0-9]*)\\\)?(Bundle\\\)?([A-Za-z0-9]+)Bundle\\\(Entity|Document|Model|PHPCR|CouchDocument|Phpcr|Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB)\\\(.*)@'; /** * The class name managed by the admin class @@ -957,8 +957,8 @@ public function getBaseRoutePattern() ); } else { - $this->baseRoutePattern = sprintf('/%s/%s/%s', - $this->urlize($matches[1], '-'), + $this->baseRoutePattern = sprintf('/%s%s/%s', + empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/', $this->urlize($matches[3], '-'), $this->urlize($matches[5], '-') ); @@ -990,9 +990,8 @@ public function getBaseRouteName() $this->urlize($matches[5]) ); } else { - - $this->baseRouteName = sprintf('admin_%s_%s_%s', - $this->urlize($matches[1]), + $this->baseRouteName = sprintf('admin_%s%s_%s', + empty($matches[1]) ? '' : $this->urlize($matches[1]).'_', $this->urlize($matches[3]), $this->urlize($matches[5]) ); diff --git a/Tests/Admin/AdminTest.php b/Tests/Admin/AdminTest.php index 0dc09d3aae..c85209c79a 100644 --- a/Tests/Admin/AdminTest.php +++ b/Tests/Admin/AdminTest.php @@ -437,6 +437,10 @@ public function provideGetBaseRoutePattern() 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu', '/cmf/foo/menu' ), + array( + 'AppBundle\Entity\User', + '/app/user' + ), ); } @@ -463,7 +467,7 @@ public function testGetBaseRoutePatternWithChildAdmin() */ public function testGetBaseRoutePatternWithUnreconizedClassname() { - $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin'); + $admin = new PostAdmin('sonata.post.admin.post', 'News\Entity\Post', 'SonataNewsBundle:PostAdmin'); $admin->getBaseRoutePattern(); } @@ -510,7 +514,7 @@ public function provideGetBaseRouteName() 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item', 'admin_symfony_barbar_menu_item' ), - array( + array( 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu', 'admin_cmf_foo_menu' ), @@ -522,6 +526,10 @@ public function provideGetBaseRouteName() 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu', 'admin_cmf_foo_menu' ), + array( + 'AppBundle\Entity\User', + 'admin_app_user' + ), ); } @@ -570,7 +578,7 @@ public function testGetBaseRouteNameWithChildAdmin() */ public function testGetBaseRouteNameWithUnreconizedClassname() { - $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin'); + $admin = new PostAdmin('sonata.post.admin.post', 'News\Entity\Post', 'SonataNewsBundle:PostAdmin'); $admin->getBaseRouteName(); }