Use Voter in Admin for configurationPanes

This commit is contained in:
Benoît Burnichon
2015-09-16 16:50:04 +02:00
parent 8e769ad657
commit 625df89bb7
2 changed files with 17 additions and 36 deletions

View File

@@ -10,19 +10,12 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Plugin\PluginMetadataInterface;
use Alchemy\WebGalleryPlugin\Controller\BaseController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
class PluginsController class PluginsController extends BaseController
{ {
/** @var Application */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function indexAction() public function indexAction()
{ {
return $this->render('admin/plugins/index.html.twig', [ return $this->render('admin/plugins/index.html.twig', [
@@ -40,33 +33,22 @@ class PluginsController
throw new \InvalidArgumentException('Expects a valid plugin name.'); throw new \InvalidArgumentException('Expects a valid plugin name.');
} }
return $this->render('admin/plugins/show.html.twig', [ /** @var PluginMetadataInterface $plugin */
'plugin' => $this->app['plugins'][$pluginName], $plugin = $this->app['plugins'][$pluginName];
]);
}
/** $configurationTabs = [];
* @param string $view
* @param array $parameters
* @param Response|null $response
* @return Response
*/
public function render($view, array $parameters = array(), Response $response = null)
{
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
if ($response instanceof StreamedResponse) { foreach ($plugin->getConfigurationTabServiceIds() as $tabName => $serviceId) {
$response->setCallback(function () use ($twig, $view, $parameters) { $configurationTab = $this->app[$serviceId];
$twig->display($view, $parameters);
}); if ($this->isGranted('VIEW', $configurationTab)) {
} else { $configurationTabs[$tabName] = $configurationTab;
if (null === $response) {
$response = new Response();
} }
$response->setContent($twig->render($view, $parameters));
} }
return $response; return $this->render('admin/plugins/show.html.twig', [
'plugin' => $this->app['plugins'][$pluginName],
'configurationTabs' => $configurationTabs,
]);
} }
} }

View File

@@ -9,8 +9,7 @@
<div> <div>
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" id="configurationTabs"> <ul class="nav nav-tabs" id="configurationTabs">
{% for divId, configurationTabServiceId in plugin.configurationTabServiceIds %} {% for divId, configurationTab in configurationTabs %}
{% set configurationTab = app[configurationTabServiceId] %}
{% set tabTitle = configurationTab.title %} {% set tabTitle = configurationTab.title %}
<li role="presentation"><a href="#{{ divId }}" aria-controls="{{ divId }}" role="tab" data-toggle="tab" data-url="{{ configurationTab.url }}">{% trans tabTitle plugin.localeTextDomain %}</a></li> <li role="presentation"><a href="#{{ divId }}" aria-controls="{{ divId }}" role="tab" data-toggle="tab" data-url="{{ configurationTab.url }}">{% trans tabTitle plugin.localeTextDomain %}</a></li>
{% endfor %} {% endfor %}
@@ -19,7 +18,7 @@
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
{% for divId, configurationTabServiceId in plugin.configurationTabServiceIds %} {% for divId, configurationTab in configurationTabs %}
<div role="tabpanel" class="tab-pane fade" id="{{ divId }}"></div> <div role="tabpanel" class="tab-pane fade" id="{{ divId }}"></div>
{% endfor %} {% endfor %}
<div role="tabpanel" class="tab-pane fade in active" id="about"> <div role="tabpanel" class="tab-pane fade in active" id="about">