/** * {@inheritdoc} */ public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) { $parameters = $route_match->getParameters()->all(); $entity_type_id = $parameters['entity_type_id']; // Attempt to load the content entity. if (isset($parameters[$entity_type_id]) && $parameters[$entity_type_id] instanceof ContentEntityInterface) { $this->contentEntity = $parameters[$entity_type_id]; } return $this->entityLayoutManager->getFromRouteMatch($route_match); }
/** * Get the entity layout object from the route match object. * * @return EntityLayoutInterface */ protected function getEntityLayoutFromRouteMatch() { if (!$this->entityLayout) { $this->entityLayout = $this->entityLayoutManager->getFromRouteMatch($this->getRouteMatch()); } return $this->entityLayout; }
/** * Get the entity layout from the route match parameters. * * @return EntityLayoutInterface */ public function getEntityLayoutFromRouteMatch() { if (!$this->entityLayout) { $content_entity = $this->getContentEntityFromRouteMatch(); $this->entityLayout = $this->entityLayoutManager->getEntityLayout($content_entity->getEntityTypeId(), $content_entity->bundle()); } return $this->entityLayout; }
/** * Reset the content layout to the default entity layout settings by * removing all content entity blocks created for the content entity. * * @param ContentEntityInterface $entity * The content entity to remove entity layout blocks from. * * @return bool */ public function resetContentEntityLayout(ContentEntityInterface $entity) { $content_blocks = $this->getContentBlocksByEntity($entity); try { $this->entityTypeManager->getStorage('entity_layout_block')->delete($content_blocks); } catch (EntityStorageException $e) { return FALSE; } $entity_layout = $this->entityLayoutManager->getEntityLayout($entity->getEntityTypeId(), $entity->bundle()); $this->transferDefaultBlocks($entity_layout, $entity); return TRUE; }
/** * Override the routes for each content entity that has been configured by * entity layout. * * @param RouteCollection $collection */ protected function buildEntityLayoutRoutes(RouteCollection $collection) { $requirements = ['_entity_access' => 'entity_layout.view']; $parameters = ['entity_layout' => ['type' => 'entity:entity_layout']]; /* @var $entity_layout EntityLayoutInterface */ foreach ($this->entityLayoutManager->getAll() as $entity_layout) { $target_entity_id = $entity_layout->getTargetEntityType(); $entities = $this->loadEntities($target_entity_id, $entity_layout->getTargetBundle()); $entity_parameters = [$target_entity_id => ['type' => "entity:{$target_entity_id}"]]; foreach ($entities as $entity) { $entity_path = $entity->toUrl('canonical')->getInternalPath(); $route_name = "entity_layout.{$entity->getEntityTypeId()}.{$entity->id()}"; $defaults = ['_entity_view' => 'entity_layout', '_title' => $entity->label(), 'entity_layout' => $entity_layout->id(), 'entity_type_id' => $entity->getEntityTypeId(), $target_entity_id => $entity->id()]; $options = ['_entity_layout' => TRUE, 'parameters' => $parameters + $entity_parameters]; $route = new Route($entity_path, $defaults, $requirements, $options); $collection->add($route_name, $route); } } }
/** * Build block library for a config entity. * * @param RouteMatch $route_match * The route match object. * * @return array */ public function configBlockLibrary(RouteMatch $route_match) { $entity_layout = $this->entityLayoutManager->getFromRouteMatch($route_match); return $this->buildBlockLibrary($entity_layout); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->entityLayoutManager->removeContentBlock($this->entityLayoutBlock); drupal_set_message($this->t('The @label block has been removed', ['@label' => $this->entityLayoutBlock->label()])); $form_state->setRedirectUrl($this->getCancelUrl()); }