/** * @param BlockEvent $event * * @return BlockInterface */ public function onBlock(BlockEvent $event) { $block = new Block(); $block->setSettings($event->getSettings()); $block->setType($this->getName()); $event->addBlock($block); }
/** * @param BlockEvent */ public function onBlock(BlockEvent $event) { $block = new Block(); $block->setSettings($event->getSettings()); $block->setName('sonata_translation.block.locale_switcher'); $block->setType('sonata_translation.block.locale_switcher'); $event->addBlock($block); }
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); }
/** * @param BlockEvent $event */ public function onBlock(BlockEvent $event, $eventName) { $settings = $event->getSettings(); if ($eventName == 'sonata.block.event.sonata.admin.show.top') { $settings['locale_switcher_route'] = 'show'; } $block = new Block(); $block->setSettings($settings); $block->setName('sonata_translation.block.locale_switcher'); $block->setType('sonata_translation.block.locale_switcher'); $event->addBlock($block); }
/** * 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); }
/** * @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); }
/** * 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; } } }
public function testBlockEvent() { $blockEvent = new BlockEvent(); $this->assertEmpty($blockEvent->getSettings()); $blockEvent->addBlock($this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface')); $this->assertCount(1, $blockEvent->getBlocks()); $blockEvent->addBlock($this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface')); $this->assertCount(2, $blockEvent->getBlocks()); $this->assertNull($blockEvent->getSetting('fake')); $this->assertEquals(1, $blockEvent->getSetting('fake', 1)); }
/** * @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); }
/** * @param BlockEvent $event * * @return array */ protected function getEventBlocks(BlockEvent $event) { $results = array(); foreach ($event->getBlocks() as $block) { $results[] = array($block->getId(), $block->getType()); } return $results; }
/** * @param BlockEvent $event * * @return array */ protected function getEventListeners(BlockEvent $event) { $results = array(); foreach ($this->eventDispatcher->getListeners($event->getName()) as $listener) { if (is_object($listener[0])) { $results[] = get_class($listener[0]); } else { if (is_string($listener[0])) { $results[] = $listener[0]; } else { if ($listener instanceof \Closure) { $results[] = '{closure}()'; } else { $results[] = 'Unkown type!'; } } } } return $results; }