public function upgradeBkeyToFqClassname(KernelInterface $kernel, BlockEntity $blockEntity) { $moduleName = $blockEntity->getModule()->getName(); try { $moduleBundle = $kernel->getModule($moduleName); $blockClassName = $moduleBundle->getNamespace() . '\\Block\\' . ucwords($blockEntity->getBkey()); $blockClassName = preg_match('/.*Block$/', $blockClassName) ? $blockClassName : $blockClassName . 'Block'; } catch (\Exception $e) { $moduleBundle = null; $blockClassName = '\\' . ucwords($moduleName) . '\\' . 'Block\\' . ucwords($blockEntity->getBkey()); $blockClassName = preg_match('/.*Block$/', $blockClassName) ? $blockClassName : $blockClassName . 'Block'; $blockClassNameOld = '\\' . ucwords($moduleName) . '_' . 'Block_' . ucwords($blockEntity->getBkey()); $blockClassName = class_exists($blockClassName) ? $blockClassName : $blockClassNameOld; } return "{$moduleName}:{$blockClassName}"; }
/** * @Route("/delete/{bid}", requirements={"bid" = "^[1-9]\d*$"}) * @Theme("admin") * * Delete a block. * * @param Request $request * @param BlockEntity $blockEntity * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function deleteAction(Request $request, BlockEntity $blockEntity) { if (!$this->hasPermission('ZikulaBlocksModule::', $blockEntity->getBkey() . ':' . $blockEntity->getTitle() . ':' . $blockEntity->getBid(), ACCESS_DELETE)) { throw new AccessDeniedException(); } $form = $this->createFormBuilder()->add('delete', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType', ['label' => 'Delete'])->add('cancel', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType', ['label' => 'Cancel'])->getForm(); $form->handleRequest($request); if ($form->isValid()) { if ($form->get('delete')->isClicked()) { $em = $this->getDoctrine()->getManager(); $em->remove($blockEntity); $em->flush(); $this->addFlash('status', __('Done! Block deleted.')); } if ($form->get('cancel')->isClicked()) { $this->addFlash('status', __('Operation cancelled.')); } return $this->redirect($this->generateUrl('zikulablocksmodule_admin_view')); } return $this->render('ZikulaBlocksModule:Admin:delete.html.twig', ['form' => $form->createView(), 'block' => $blockEntity]); }
/** * 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); }