Skip to content

Commit

Permalink
victoire businessLink read businessTemplates parameters for template Id
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie-Lucas committed Feb 24, 2016
1 parent 41b8eb7 commit e0aa1e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Bundle/WidgetBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
- @victoire_business_page.business_page_helper
- @victoire_page.page_helper
- @doctrine.orm.entity_manager
- @victoire_core.url_builder
- %victoire_core.businessTemplates%
tags:
- { name: twig.extension }

Expand Down
20 changes: 19 additions & 1 deletion Bundle/WidgetBundle/Twig/LinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,29 @@ class LinkExtension extends \Twig_Extension
protected $BusinessPageHelper; // @victoire_business_page.business_page_helper
protected $pageHelper;
protected $em; // @doctrine.orm.entity_manager
protected $abstractBusinessTemplates;

/**
* LinkExtension constructor.
*
* @param Router $router
* @param RequestStack $requestStack
* @param $analytics
* @param BusinessEntityHelper $businessEntityHelper
* @param BusinessPageHelper $BusinessPageHelper
* @param PageHelper $pageHelper
* @param EntityManager $em
* @param array $abstractBusinessTemplates
*/
public function __construct(
Router $router,
RequestStack $requestStack,
$analytics,
BusinessEntityHelper $businessEntityHelper,
BusinessPageHelper $BusinessPageHelper,
PageHelper $pageHelper,
EntityManager $em
EntityManager $em,
$abstractBusinessTemplates = []
) {
$this->router = $router;
$this->request = $requestStack->getCurrentRequest();
Expand All @@ -39,6 +53,7 @@ public function __construct(
$this->BusinessPageHelper = $BusinessPageHelper;
$this->pageHelper = $pageHelper;
$this->em = $em;
$this->abstractBusinessTemplates = $abstractBusinessTemplates;
}

/**
Expand Down Expand Up @@ -212,6 +227,9 @@ public function victoireMenuLink($parameters, $label, $attr = [])

public function victoireBusinessLink($businessEntityInstance, $templateId = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
if (isset($this->abstractBusinessTemplates[$templateId])) {
$templateId = $this->abstractBusinessTemplates[$templateId];
}
if (!$templateId) {
$templateId = $this->BusinessPageHelper
->guessBestPatternIdForEntity(new \ReflectionClass($businessEntityInstance), $businessEntityInstance->getId(), $this->em);
Expand Down

0 comments on commit e0aa1e7

Please sign in to comment.