/** * Detects if there is a custom controller to use to render a Block. * * @param FilterControllerEvent $event * * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function getController(FilterControllerEvent $event) { $request = $event->getRequest(); // Only taking page related controller (i.e. ez_page:viewBlock or ez_page:viewBlockById) if (strpos($request->attributes->get('_controller'), 'ez_page:') === false) { return; } try { if ($request->attributes->has('id')) { $valueObject = $this->pageService->loadBlock($request->attributes->get('id')); $request->attributes->set('block', $valueObject); } elseif ($request->attributes->get('block') instanceof Block) { $valueObject = $request->attributes->get('block'); $request->attributes->set('id', $valueObject->id); } } catch (UnauthorizedException $e) { throw new AccessDeniedException(); } if (!isset($valueObject)) { $this->logger->error('Could not resolve a page controller, invalid value object to match.'); return; } $controllerReference = $this->controllerManager->getControllerReference($valueObject, 'block'); if (!$controllerReference instanceof ControllerReference) { return; } $request->attributes->set('_controller', $controllerReference->controller); $event->setController($this->controllerResolver->getController($request)); }
public function injectValidItems(FilterViewParametersEvent $event) { $view = $event->getView(); if ($view instanceof BlockView) { $event->getParameterBag()->set('valid_items', $this->pageService->getValidBlockItems($view->getBlock())); } }
public function injectValidContentInfoItems(FilterViewParametersEvent $event) { $view = $event->getView(); if ($view instanceof BlockView && $this->pageService instanceof CoreBundlePageService) { $event->getParameterBag()->set('valid_contentinfo_items', $this->pageService->getValidBlockItemsAsContentInfo($view->getBlock())); } }
/** * Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct. * * @param mixed $fieldSettings * * @return \eZ\Publish\SPI\FieldType\ValidationError[] */ public function validateFieldSettings($fieldSettings) { $validationErrors = array(); foreach ($fieldSettings as $name => $value) { if (isset($this->settingsSchema[$name])) { switch ($name) { case 'defaultLayout': if ($value !== '' && !in_array($value, $this->pageService->getAvailableZoneLayouts())) { $validationErrors[] = new ValidationError("Layout '{$value}' for setting '%setting%' is not available", null, array('setting' => $name), "[{$name}]"); } break; } } else { $validationErrors[] = new ValidationError("Setting '%setting%' is unknown", null, array('setting' => $name), "[{$name}]"); } } return $validationErrors; }
public function buildView(array $parameters) { $view = new BlockView(); if (isset($parameters['id'])) { $view->setBlock($this->pageService->loadBlock($parameters['id'])); } elseif ($parameters['block'] instanceof Block) { $view->setBlock($parameters['block']); } $this->viewConfigurator->configure($view); // deprecated controller actions are replaced with their new equivalent, viewAction if (!$view->getControllerReference() instanceof ControllerReference) { if (in_array($parameters['_controller'], ['ez_page:viewBlock', 'ez_page:viewBlockById'])) { $view->setControllerReference(new ControllerReference('ez_page:viewAction')); } } $this->viewParametersInjector->injectViewParameters($view, $parameters); return $view; }
public function testLoadBlock() { $contentId = 12; $blockId = 'abc0123'; $block = new Block(array('id' => $blockId)); $zone = new Zone(array('blocks' => array($block))); $page = new Page(array('zones' => array($zone))); $value = new Value($page); $field = new Field(array('value' => $value)); $content = new Content(array('internalFields' => array($field))); $this->pageService->setStorageGateway($this->storageGateway); $this->storageGateway->expects($this->once())->method('getContentIdByBlockId')->with($blockId)->will($this->returnValue($contentId)); $this->contentService->expects($this->once())->method('loadContent')->with($contentId)->will($this->returnValue($content)); // Calling assertion twice to test cache (comes along with storage gateway's // getLocationIdByBlockId() that should be called only once. See above) $this->assertSame($block, $this->pageService->loadBlock($blockId)); $this->assertSame($block, $this->pageService->loadBlock($blockId)); }
/** * Renders the block with given $id. * * This method can be used with ESI rendering strategy. * * @uses self::viewBlock() * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If block could not be found. * * @param mixed $id Block id * @param array $params * @param array $cacheSettings settings for the HTTP cache, 'smax-age' and * 'max-age' are checked. * * @return \Symfony\Component\HttpFoundation\Response */ public function viewBlockById($id, array $params = array(), array $cacheSettings = array()) { return $this->viewBlock($this->pageService->loadBlock($id), $params, $cacheSettings); }