Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to use businessTemplate constant to generate business links #348

Merged
merged 2 commits into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Bundle/CoreBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public function getConfigTreeBuilder()
->defaultValue(['%kernel.root_dir%/../src', '%kernel.root_dir%/../vendor/victoire/victoire/Bundle/BlogBundle', '%kernel.root_dir%/../vendor/friendsofvictoire'])
->end()
->end()
->children()
->variableNode('businessTemplates')
->defaultNull()
->treatNullLike([])
->end()
->end()
->children()
->variableNode('applicative_bundle')
->defaultNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter(
'victoire_core.base_paths', $config['base_paths']
);
$container->setParameter(
'victoire_core.businessTemplates', $config['businessTemplates']
);
}
}
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