Chris@0: routeMatch = $route_match; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getLabel() { Chris@0: return t('Layout Builder'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getContext($entity_type_id = NULL) { Chris@0: if (!$entity_type_id) { Chris@0: throw new \LogicException('Missing entity type ID'); Chris@0: } Chris@0: Chris@0: $display = $this->getDisplay($entity_type_id); Chris@0: return ($display && $display->isOverridable()) ? '1' : '0'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getCacheableMetadata($entity_type_id = NULL) { Chris@0: if (!$entity_type_id) { Chris@0: throw new \LogicException('Missing entity type ID'); Chris@0: } Chris@0: Chris@0: $cacheable_metadata = new CacheableMetadata(); Chris@0: if ($display = $this->getDisplay($entity_type_id)) { Chris@0: $cacheable_metadata->addCacheableDependency($display); Chris@0: } Chris@0: return $cacheable_metadata; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the entity view display for a given entity type and view mode. Chris@0: * Chris@0: * @param string $entity_type_id Chris@0: * The entity type ID. Chris@0: * Chris@0: * @return \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface|null Chris@0: * The entity view display, if it exists. Chris@0: */ Chris@0: protected function getDisplay($entity_type_id) { Chris@0: if ($entity = $this->routeMatch->getParameter($entity_type_id)) { Chris@0: if ($entity instanceof OverridesSectionStorageInterface) { Chris@0: return $entity->getDefaultSectionStorage(); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }