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