/** * Build block library for a content entity. * * @param RouteMatch $route_match * The route match object. * * @return array */ public function contentBlockLibrary(RouteMatch $route_match) { $parameters = $route_match->getParameters(); $entity_type_id = $parameters->get('entity_type_id'); /** @var ContentEntityInterface $content_entity */ $content_entity = $parameters->get($entity_type_id); $entity_layout = $this->entityLayoutManager->getEntityLayout($entity_type_id, $content_entity->bundle()); return $this->buildBlockLibrary($entity_layout, $content_entity); }
/** * 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; }