/** * {@inheritdoc} */ public function get($meta, array $settings = array()) { if (!$meta instanceof BlockInterface) { $block = $this->blockLoader->load($meta); if (is_array($meta) && isset($meta['settings'])) { // merge user settings $settings = array_merge($meta['settings'], $settings); } } else { $block = $meta; } if (!$block instanceof BlockInterface) { return false; } $originalSettings = $settings; try { $settings = $this->resolve($block, array_merge($block->getSettings(), $settings)); } catch (ExceptionInterface $e) { if ($this->logger) { $this->logger->error(sprintf('[cms::blockContext] block.id=%s - error while resolving options - %s', $block->getId(), $e->getMessage())); } $settings = $this->resolve($block, $settings); } $blockContext = new BlockContext($block, $settings); $this->setDefaultExtraCacheKeys($blockContext, $originalSettings); return $blockContext; }
/** * @param Request $request * * @throws NotFoundHttpException * @throws AccessDeniedHttpException * * @return mixed */ public function cacheAction(Request $request) { $parameters = array_merge($request->query->all(), $request->attributes->all()); if ($request->get('_token') != $this->computeHash($parameters)) { throw new AccessDeniedHttpException('Invalid token'); } $block = $this->blockLoader->load(array('name' => $request->get('block_id'))); if (!$block) { throw new NotFoundHttpException(sprintf('Block not found : %s', $request->get('block_id'))); } $settings = $request->get(BlockContextManagerInterface::CACHE_KEY, array()); if (!is_array($settings)) { throw new \RuntimeException(sprintf('Query string parameter `%s` is not an array', BlockContextManagerInterface::CACHE_KEY)); } return $this->blockRenderer->render($this->blockContextManager->get($block, $settings)); }