You are here

public function Library::isApplicable in Layout builder library 8

Determines if this section storage is applicable for the current contexts.

@internal This method is intended to be called by \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface::findByContext().

Parameters

\Drupal\Core\Cache\RefinableCacheableDependencyInterface $cacheability: Refinable cacheability object, typically provided by the section storage manager. When implementing this method, populate $cacheability with any information that affects whether this storage is applicable.

Return value

bool TRUE if this section storage is applicable, FALSE otherwise.

Overrides SectionStorageInterface::isApplicable

See also

\Drupal\Core\Cache\RefinableCacheableDependencyInterface

File

src/Plugin/SectionStorage/Library.php, line 262

Class

Library
Defines a class for library based layout storage.

Namespace

Drupal\layout_library\Plugin\SectionStorage

Code

public function isApplicable(RefinableCacheableDependencyInterface $cacheability) {

  // Since the 'layout' context must be marked optional, ensure that it is set
  // before proceeding.
  $is_library_enabled = FALSE;
  $values = $this
    ->getContextValues();
  if (!is_null($values['layout'])) {
    $entity = $values['layout']
      ->getTargetEntityType();
    $bundle = $values['layout']
      ->getTargetBundle();
    $view_mode = $values['view_mode'];
    $entity_view_display = $this->entityTypeManager
      ->getStorage('entity_view_display')
      ->load($entity . '.' . $bundle . '.' . $view_mode);
    if ($entity_view_display) {
      $is_library_enabled = $entity_view_display
        ->getThirdPartySetting('layout_library', 'enable');
    }
  }
  return $this
    ->getSectionList() && $is_library_enabled;
}