mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 06:44:59 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,27 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2014 Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Routing;
|
||||
|
||||
use Chill\MainBundle\Routing\MenuComposer;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Twig\Environment;
|
||||
@@ -29,90 +16,86 @@ use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Add the filter 'chill_menu'
|
||||
*
|
||||
* @author Julien Fastré <julien arobase fastre point info>
|
||||
* Add the filter 'chill_menu'.
|
||||
*/
|
||||
class MenuTwig extends AbstractExtension implements ContainerAwareInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var MenuComposer
|
||||
*/
|
||||
private $menuComposer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
|
||||
/**
|
||||
* the default parameters for chillMenu
|
||||
*
|
||||
* @var mixed[]
|
||||
* the default parameters for chillMenu.
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
private $defaultParams = array(
|
||||
private $defaultParams = [
|
||||
'layout' => '@ChillMain/Menu/defaultMenu.html.twig',
|
||||
'args' => array(),
|
||||
'activeRouteKey' => null
|
||||
);
|
||||
|
||||
'args' => [],
|
||||
'activeRouteKey' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MenuComposer
|
||||
*/
|
||||
private $menuComposer;
|
||||
|
||||
public function __construct(MenuComposer $menuComposer)
|
||||
{
|
||||
$this->menuComposer = $menuComposer;
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [new TwigFunction('chill_menu',
|
||||
array($this, 'chillMenu'), array(
|
||||
'is_safe' => array('html'),
|
||||
'needs_environment' => true
|
||||
))
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a Menu corresponding to $menuId
|
||||
*
|
||||
* Expected params :
|
||||
* Render a Menu corresponding to $menuId.
|
||||
*
|
||||
* Expected params :
|
||||
* - args: the arguments to build the path (i.e: if pattern is /something/{bar}, args must contain {'bar': 'foo'}
|
||||
* - layout: the layout. Absolute path needed (i.e.: ChillXyzBundle:section:foo.html.twig)
|
||||
* - activeRouteKey : the key active, will render the menu differently.
|
||||
*
|
||||
*
|
||||
* @deprecated link: see https://redmine.champs-libres.coop/issues/179 for more informations
|
||||
*
|
||||
*
|
||||
* @param string $menuId
|
||||
* @param mixed[] $params
|
||||
*/
|
||||
public function chillMenu(Environment $env, $menuId, array $params = array())
|
||||
public function chillMenu(Environment $env, $menuId, array $params = [])
|
||||
{
|
||||
$resolvedParams = array_merge($this->defaultParams, $params);
|
||||
|
||||
$layout = $resolvedParams['layout'];
|
||||
unset($resolvedParams['layout']);
|
||||
|
||||
|
||||
if ($this->menuComposer->hasLocalMenuBuilder($menuId) === false) {
|
||||
$resolvedParams['routes'] = $this->menuComposer->getRoutesFor($menuId, $resolvedParams);
|
||||
|
||||
return $env->render($layout, $resolvedParams);
|
||||
} else {
|
||||
$resolvedParams['menus'] = $this->menuComposer->getMenuFor($menuId, $resolvedParams);
|
||||
|
||||
|
||||
return $env->render($layout, $resolvedParams);
|
||||
}
|
||||
$resolvedParams['menus'] = $this->menuComposer->getMenuFor($menuId, $resolvedParams);
|
||||
|
||||
return $env->render($layout, $resolvedParams);
|
||||
}
|
||||
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [new TwigFunction(
|
||||
'chill_menu',
|
||||
[$this, 'chillMenu'],
|
||||
[
|
||||
'is_safe' => ['html'],
|
||||
'needs_environment' => true,
|
||||
]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'chill_menu';
|
||||
}
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
public function setContainer(?ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user