Skip to content

Commit 8e7a2b7

Browse files
committed
Merge pull request #213 from gregumo/master
Use EntityManager in BusinessPageHelper to get correct entity name
2 parents 7de6a52 + 2bf4726 commit 8e7a2b7

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

Bundle/BusinessPageBundle/Helper/BusinessPageHelper.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,25 @@ public function getIdentifierPositionInUrl(BusinessTemplate $bepPattern)
176176

177177
/**
178178
* Guess the best pattern to represent given reflectionClass
179+
*
179180
* @param \ReflectionClass $refClass
180181
* @param integer $entityId
182+
* @param EntityManager $em
181183
* @param string $originalRefClassName When digging into parentClass, we do not have to forget originalClass to be able to get reference after all
182184
*
183185
* @return View
186+
* @throws \Exception
184187
*/
185-
public function guessBestPatternIdForEntity($refClass, $entityId, $originalRefClassName = null)
188+
public function guessBestPatternIdForEntity($refClass, $entityId, $em, $originalRefClassName = null)
186189
{
190+
$refClassName = $em->getClassMetadata($refClass->name)->name;
191+
187192
$viewReference = null;
188193
if (!$originalRefClassName) {
189-
$originalRefClassName = $refClass->name;
194+
$originalRefClassName = $refClassName;
190195
}
191196

192-
$businessEntity = $this->businessEntityHelper->findByEntityClassname($refClass->name);
197+
$businessEntity = $this->businessEntityHelper->findByEntityClassname($refClassName);
193198

194199
if ($businessEntity) {
195200
$parameters = array(
@@ -203,9 +208,9 @@ public function guessBestPatternIdForEntity($refClass, $entityId, $originalRefCl
203208
if (!$viewReference) {
204209
$parentRefClass = $refClass->getParentClass();
205210
if ($parentRefClass) {
206-
$viewReference['patternId'] = $this->guessBestPatternIdForEntity($parentRefClass, $entityId, $originalRefClassName);
211+
$viewReference['patternId'] = $this->guessBestPatternIdForEntity($parentRefClass, $entityId, $em, $originalRefClassName);
207212
} else {
208-
throw new \Exception(sprintf('Cannot find a BusinessTemplate that can display the requested BusinessEntity ("%s", "%s".)', $refClass->name, $entityId));
213+
throw new \Exception(sprintf('Cannot find a BusinessTemplate that can display the requested BusinessEntity ("%s", "%s".)', $refClassName, $entityId));
209214
}
210215
}
211216

Bundle/PageBundle/Controller/BasePageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function showBusinessPageByIdAction($entityId, $type)
5050
$refClass = new \ReflectionClass($entity);
5151

5252
$patternId = $this->container->get('victoire_business_page.business_page_helper')
53-
->guessBestPatternIdForEntity($refClass, $entityId);
53+
->guessBestPatternIdForEntity($refClass, $entityId, $this->container->get('doctrine.orm.entity_manager'));
5454

5555
$page = $this->container->get('victoire_page.page_helper')->findPageByParameters(array(
5656
'viewId' => $patternId,

Bundle/WidgetBundle/Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ services:
6262
- @victoire_core.helper.business_entity_helper
6363
- @victoire_business_page.business_page_helper
6464
- @victoire_page.page_helper
65+
- @doctrine.orm.entity_manager
6566
tags:
6667
- { name: twig.extension }
6768

Bundle/WidgetBundle/Twig/LinkExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Victoire\Bundle\WidgetBundle\Twig;
44

5+
use Doctrine\ORM\EntityManager;
56
use Symfony\Bundle\FrameworkBundle\Routing\Router;
67
use Symfony\Component\HttpFoundation\RequestStack;
78
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -20,14 +21,16 @@ class LinkExtension extends \Twig_Extension
2021
protected $businessEntityHelper; // @victoire_business_page.business_entity_helper
2122
protected $BusinessPageHelper; // @victoire_business_page.business_page_helper
2223
protected $pageHelper;
24+
protected $em; // @doctrine.orm.entity_manager
2325

2426
public function __construct(
2527
Router $router,
2628
RequestStack $requestStack,
2729
$analytics,
2830
BusinessEntityHelper $businessEntityHelper,
2931
BusinessPageHelper $BusinessPageHelper,
30-
PageHelper $pageHelper
32+
PageHelper $pageHelper,
33+
EntityManager $em
3134
)
3235
{
3336
$this->router = $router;
@@ -36,6 +39,7 @@ public function __construct(
3639
$this->businessEntityHelper = $businessEntityHelper;
3740
$this->BusinessPageHelper = $BusinessPageHelper;
3841
$this->pageHelper = $pageHelper;
42+
$this->em = $em;
3943
}
4044
/**
4145
* Returns a list of functions to add to the existing list.
@@ -194,7 +198,7 @@ public function victoireBusinessLink($businessEntityInstance, $patternId = null,
194198
{
195199
if (!$patternId) {
196200
$patternId = $this->BusinessPageHelper
197-
->guessBestPatternIdForEntity(new \ReflectionClass($businessEntityInstance), $businessEntityInstance->getId());
201+
->guessBestPatternIdForEntity(new \ReflectionClass($businessEntityInstance), $businessEntityInstance->getId(), $this->em);
198202
}
199203

200204
$page = $this->pageHelper->findPageByParameters(array(

0 commit comments

Comments
 (0)