コード例 #1
0
 public function testRenderEventWithListeners()
 {
     $blockService = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceInterface');
     $blockService->expects($this->once())->method('getJavascripts')->will($this->returnValue(array()));
     $blockService->expects($this->once())->method('getStylesheets')->will($this->returnValue(array()));
     $blockServiceManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceManagerInterface');
     $blockServiceManager->expects($this->any())->method('get')->will($this->returnValue($blockService));
     $blockRenderer = $this->getMock('Sonata\\BlockBundle\\Block\\BlockRendererInterface');
     $blockRenderer->expects($this->once())->method('render')->will($this->returnValue(new Response('<span>test</span>')));
     $blockContextManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockContextManagerInterface');
     $blockContextManager->expects($this->once())->method('get')->will($this->returnCallback(function (BlockInterface $block) {
         $context = new BlockContext($block, $block->getSettings());
         return $context;
     }));
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $eventDispatcher->expects($this->once())->method('dispatch')->will($this->returnCallback(function ($name, BlockEvent $event) {
         $block = new Block();
         $block->setId(1);
         $block->setSettings(array('use_cache' => false));
         $block->setType('test');
         $event->addBlock($block);
         return $event;
     }));
     $helper = new BlockHelper($blockServiceManager, array(), $blockRenderer, $blockContextManager, $eventDispatcher);
     $this->assertEquals('<span>test</span>', $helper->renderEvent('my.event'));
 }
コード例 #2
0
 public function onBlock(BlockEvent $blockEvent)
 {
     $block = new Block();
     $block->setId(uniqid());
     // set a fake id
     $block->setSettings($blockEvent->getSettings());
     $block->setType('admin.form_javascripts.block');
     $blockEvent->addBlock($block);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function load($configuration)
 {
     $block = new Block();
     $block->setId(uniqid());
     $block->setType($configuration['type']);
     $block->setSettings($this->getSettings($configuration));
     $block->setEnabled(true);
     $block->setCreatedAt(new \DateTime());
     $block->setUpdatedAt(new \DateTime());
     return $block;
 }
コード例 #4
0
 /**
  * Add blocks services to event.
  *
  * @param BlockEvent $event
  */
 public function onBlock(BlockEvent $event)
 {
     $identifier = $event->getSetting('id', null);
     if ($identifier == null) {
         return;
     }
     $block = new Block();
     $block->setId(uniqid());
     $block->setSettings($event->getSettings());
     $block->setType($this->blockService->getName());
     $event->addBlock($block);
 }
コード例 #5
0
 /**
  * @param BlockEvent $event
  */
 public function onBlock(BlockEvent $event)
 {
     $content = 'This block is coming from inline event from the template';
     if ($event->getSetting('admin') instanceof AdminInterface && $event->getSetting('action') == 'edit') {
         $admin = $event->getSetting('admin');
         $content = sprintf("<p class='well'>The admin subject is <strong>%s</strong></p>", $admin->toString($admin->getSubject()));
     }
     $block = new Block();
     $block->setId(uniqid());
     $block->setSettings(array('content' => $event->getSetting('content', $content)));
     $block->setType('sonata.block.service.text');
     $event->addBlock($block);
 }
コード例 #6
0
 /**
  * @param BlockEvent $event
  */
 public function onBlock(BlockEvent $event)
 {
     if (!$this->optionService->get('twomartens.core', 'showSystemStats')->getValue()) {
         return;
     }
     $variables = ['systemData' => [['key' => $this->translator->trans('acp.dashboard.blocks.systemstats.os', [], 'TwoMartensCoreBundle'), 'value' => PHP_OS], ['key' => $this->translator->trans('acp.dashboard.blocks.systemstats.webserver', [], 'TwoMartensCoreBundle'), 'value' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : ''], ['key' => $this->translator->trans('acp.dashboard.blocks.systemstats.php', [], 'TwoMartensCoreBundle'), 'value' => PHP_VERSION]]];
     $content = $this->templating->render('TwoMartensCoreBundle:blocks:systemStatsBlock.html.twig', $variables);
     $block = new Block();
     $block->setId(uniqid());
     $block->setSetting('content', $content);
     $block->setType('sonata.block.service.text');
     $event->addBlock($block);
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function load($configuration)
 {
     if (!in_array($configuration['type'], $this->types)) {
         throw new \RuntimeException(sprintf('The block type "%s" does not exist', $configuration['type']));
     }
     $block = new Block();
     $block->setId(uniqid());
     $block->setType($configuration['type']);
     $block->setEnabled(true);
     $block->setCreatedAt(new \DateTime());
     $block->setUpdatedAt(new \DateTime());
     $block->setSettings(isset($configuration['settings']) ? $configuration['settings'] : array());
     return $block;
 }
コード例 #8
0
 /**
  * Add context related BlockService, if found.
  *
  * @param BlockEvent $event
  */
 public function onBlock(BlockEvent $event)
 {
     $context = $event->getSetting('context', null);
     if ($context == null) {
         return;
     }
     foreach ($this->blockServices as $type => $blockService) {
         if ($blockService->handleContext($context)) {
             $block = new Block();
             $block->setId(uniqid());
             $block->setSettings($event->getSettings());
             $block->setType($type);
             $event->addBlock($block);
             return;
         }
     }
 }
コード例 #9
0
    public function testRenderEventWithListeners()
    {
        $blockService = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceInterface');
        $blockService->expects($this->once())->method('getJavascripts')->will($this->returnValue(array('/js/base.js')));
        $blockService->expects($this->once())->method('getStylesheets')->will($this->returnValue(array('/css/base.css')));
        $blockServiceManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockServiceManagerInterface');
        $blockServiceManager->expects($this->any())->method('get')->will($this->returnValue($blockService));
        $blockRenderer = $this->getMock('Sonata\\BlockBundle\\Block\\BlockRendererInterface');
        $blockRenderer->expects($this->once())->method('render')->will($this->returnValue(new Response('<span>test</span>')));
        $blockContextManager = $this->getMock('Sonata\\BlockBundle\\Block\\BlockContextManagerInterface');
        $blockContextManager->expects($this->once())->method('get')->will($this->returnCallback(function (BlockInterface $block) {
            $context = new BlockContext($block, $block->getSettings());
            return $context;
        }));
        $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
        $eventDispatcher->expects($this->once())->method('dispatch')->will($this->returnCallback(function ($name, BlockEvent $event) {
            $block = new Block();
            $block->setId(1);
            $block->setSettings(array('use_cache' => false));
            $block->setType('test');
            $event->addBlock($block);
            return $event;
        }));
        $helper = new BlockHelper($blockServiceManager, array(), $blockRenderer, $blockContextManager, $eventDispatcher);
        $this->assertEquals('<span>test</span>', $helper->renderEvent('my.event'));
        $this->assertEquals(trim($helper->includeJavascripts('screen', '/application')), '<script src="/application/js/base.js" type="text/javascript"></script>');
        $this->assertEquals(trim($helper->includeJavascripts('screen', '')), '<script src="/js/base.js" type="text/javascript"></script>');
        $this->assertEquals($helper->includeStylesheets('screen', '/application'), <<<EXPECTED
<style type='text/css' media='screen'>
@import url(/application/css/base.css);
</style>
EXPECTED
);
        $this->assertEquals($helper->includeStylesheets('screen', ''), <<<EXPECTED
<style type='text/css' media='screen'>
@import url(/css/base.css);
</style>
EXPECTED
);
    }