Example #1
0
 /**
  * Get an array of Blocks that are available by scanning the filesystem.
  * Optionally only retrieve the blocks of one module.
  *
  * @param ExtensionEntity|null $module
  * @return array [[ModuleName:FqBlockClassName => ModuleDisplayName/BlockDisplayName]]
  */
 public function getAvailableBlockTypes(ExtensionEntity $module = null)
 {
     $foundBlocks = [];
     $modules = isset($module) ? [$module] : $this->extensionApi->getModulesBy(['state' => ExtensionApi::STATE_ACTIVE]);
     /** @var \Zikula\ExtensionsModule\Entity\ExtensionEntity $module */
     foreach ($modules as $module) {
         $moduleInstance = $this->extensionApi->getModuleInstanceOrNull($module->getName());
         list($nameSpace, $path) = $this->getModuleBlockPath($moduleInstance, $module->getName());
         if (!isset($path)) {
             continue;
         }
         $finder = new Finder();
         $foundFiles = $finder->files()->name('*.php')->in($path)->depth(0);
         foreach ($foundFiles as $file) {
             preg_match("/class (\\w+) (?:extends|implements) \\\\?(\\w+)/", $file->getContents(), $matches);
             $blockInstance = $this->blockFactory->getInstance($nameSpace . $matches[1], $moduleInstance);
             $foundBlocks[$module->getName() . ':' . $nameSpace . $matches[1]] = $module->getDisplayname() . '/' . $blockInstance->getType();
         }
     }
     // Add service defined blocks.
     foreach ($this->blockCollector->getBlocks() as $id => $blockInstance) {
         $className = get_class($blockInstance);
         list($moduleName, $serviceId) = explode(':', $id);
         if (isset($foundBlocks["{$moduleName}:{$className}"])) {
             // remove blocks found in file search with same class name
             unset($foundBlocks["{$moduleName}:{$className}"]);
         }
         $moduleEntity = $this->extensionApi->getModule($moduleName);
         $foundBlocks[$id] = $moduleEntity->getDisplayname() . '/' . $blockInstance->getType();
     }
     return $foundBlocks;
 }
Example #2
0
 /**
  * Display one block.
  *
  * @param BlockEntity $block
  * @param string $positionName @deprecated argument. remove at Core-2.0
  * @return string
  */
 public function showBlock(BlockEntity $block, $positionName = '')
 {
     $blockInstance = $this->blockApi->createInstanceFromBKey($block->getBkey());
     $legacy = false;
     $content = '';
     if ($blockInstance instanceof BlockControllerInterface) {
         $content = $blockInstance->display($block->getContent());
     } elseif ($blockInstance instanceof \Zikula_Controller_AbstractBlock) {
         // @todo remove at Core-2.0
         $legacy = true;
         $args = \BlockUtil::getBlockInfo($block->getBid());
         $args['position'] = $positionName;
         $content = $blockInstance->display($args);
     }
     if (!$legacy) {
         if (null !== ($moduleInstance = $this->extensionApi->getModuleInstanceOrNull($block->getModule()->getName()))) {
             // @todo can remove check for null at Core-2.0
             // add module stylesheet to page - legacy blocks load stylesheets automatically on ModUtil::load()
             $moduleInstance->addStylesheet();
         }
     }
     return $this->themeEngine->wrapBlockContentInTheme($content, $block->getTitle(), $block->getBlocktype(), $block->getBid(), $positionName, $legacy);
 }