src/Block/DashboardBlockService.php line 15

Open in your IDE?
  1. <?php 
  2. namespace App\Block
  3.  
  4. use Sonata\BlockBundle\Block\BlockContextInterface
  5. use Symfony\Component\HttpFoundation\Response
  6. use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface
  7. use Sonata\AdminBundle\Form\FormMapper
  8. use Sonata\AdminBundle\Validator\ErrorElement
  9. use Sonata\AdminBundle\Admin\Pool
  10. use Sonata\BlockBundle\Model\BlockInterface
  11. use Sonata\BlockBundle\Block\BaseBlockService
  12. use Symfony\Component\OptionsResolver\OptionsResolverInterface
  13. use Doctrine\ORM\EntityManager
  14.  
  15. class DashboardBlockService extends BaseBlockService 
  16.  
  17.     /** * @var EntityManager */
  18.     protected $em
  19.  
  20.     public function __construct(
  21.       $name
  22.       EngineInterface $templating
  23.       Pool $pool
  24.       EntityManager $em) { 
  25.         parent::__construct($name$templating); 
  26.         $this->pool $pool;
  27.         $this->em $em;
  28.     }
  29.  
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function getName()
  34.     {
  35.         return 'Dashboard';
  36.     }
  37.  
  38.  
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function execute(BlockContextInterface $blockContextResponse $response null)
  43.     {
  44.  
  45.         // Votre code métier...
  46.         echo '<pre>';var_dump('CallFromBLockService'); echo '</pre>----------';
  47.         // merge settings
  48.         $settings array_merge($this->getDefaultSettings(), $blockContext->getSettings());
  49.  
  50.         return $this->renderResponse($blockContext->getTemplate(), array(
  51.             'block'         => $blockContext->getBlock(),
  52.             'base_template' => $this->pool->getTemplate('layout'),         
  53.             'settings'      => $blockContext->getSettings(), 
  54.             'test'        => "test"
  55.         ), $response);
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     public function setDefaultSettings(OptionsResolverInterface $resolver)
  61.     {
  62.         $resolver->setDefaults(array(
  63.             'title'    => 'Tableau de bord',
  64.             'template' => 'admin/Block/TableauDeBord.html.twig' // Le template à render dans execute()
  65.         ));
  66.     }
  67.  
  68.     public function getDefaultSettings()
  69.     {
  70.         return array();
  71.     }
  72. }