91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Sonata Project package.
|
|
*
|
|
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Sonata\AdminBundle\Block;
|
|
|
|
use Sonata\AdminBundle\Admin\Pool;
|
|
use Sonata\BlockBundle\Block\BlockContextInterface;
|
|
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
|
|
/**
|
|
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
|
|
*/
|
|
class AdminListBlockService extends AbstractBlockService
|
|
{
|
|
protected $pool;
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param EngineInterface $templating
|
|
* @param Pool $pool
|
|
*/
|
|
public function __construct($name, EngineInterface $templating, Pool $pool)
|
|
{
|
|
parent::__construct($name, $templating);
|
|
|
|
$this->pool = $pool;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null)
|
|
{
|
|
$dashboardGroups = $this->pool->getDashboardGroups();
|
|
|
|
$settings = $blockContext->getSettings();
|
|
|
|
$visibleGroups = [];
|
|
foreach ($dashboardGroups as $name => $dashboardGroup) {
|
|
if (!$settings['groups'] || in_array($name, $settings['groups'])) {
|
|
$visibleGroups[] = $dashboardGroup;
|
|
}
|
|
}
|
|
|
|
return $this->renderPrivateResponse($this->pool->getTemplate('list_block'), [
|
|
'block' => $blockContext->getBlock(),
|
|
'settings' => $settings,
|
|
'admin_pool' => $this->pool,
|
|
'groups' => $visibleGroups,
|
|
], $response);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getName()
|
|
{
|
|
return 'Admin List';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function configureSettings(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'groups' => false,
|
|
]);
|
|
|
|
// Symfony < 2.6 BC
|
|
if (method_exists($resolver, 'setNormalizer')) {
|
|
$resolver->setAllowedTypes('groups', ['bool', 'array']);
|
|
} else {
|
|
$resolver->setAllowedTypes([
|
|
'groups' => ['bool', 'array'],
|
|
]);
|
|
}
|
|
}
|
|
}
|