public function PluginHelperTrait::getValuefromSectionStorage in Layout Builder Restrictions 8.2
A helper function to return values derivable from section storage.
Parameters
array $section_storage: A section storage object nested in an array.
- \Drupal\layout_builder\SectionStorageInterface, or
- \Drupal\layout_builder\OverridesSectionStorageInterface.
string $requested_value: The value to be returned.
Return value
mixed The return value depends on $requested_value parameter:
- contexts (array)
- entity (object)
- view mode (string)
- bundle (string)
- entity_type (string)
- storage (object)
- view_display (object)
4 calls to PluginHelperTrait::getValuefromSectionStorage()
- EntityViewModeRestriction::blockAllowedinContext in src/Plugin/ LayoutBuilderRestriction/ EntityViewModeRestriction.php 
- Determine whether the block being moved is allowed to the destination.
- EntityViewModeRestriction::inlineBlocksAllowedinContext in src/Plugin/ LayoutBuilderRestriction/ EntityViewModeRestriction.php 
- Returns an array of allowed inline blocks in a given context.
- EntityViewModeRestrictionByRegion::blockAllowedinContext in modules/layout_builder_restrictions_by_region/ src/ Plugin/ LayoutBuilderRestriction/ EntityViewModeRestrictionByRegion.php 
- Determine whether the block being moved is allowed to the destination.
- EntityViewModeRestrictionByRegion::inlineBlocksAllowedinContext in modules/layout_builder_restrictions_by_region/ src/ Plugin/ LayoutBuilderRestriction/ EntityViewModeRestrictionByRegion.php 
- Returns an array of allowed inline blocks in a given context.
File
- src/Traits/ PluginHelperTrait.php, line 237 
Class
- PluginHelperTrait
- Methods to help Layout Builder Restrictions plugins.
Namespace
Drupal\layout_builder_restrictions\TraitsCode
public function getValuefromSectionStorage(array $section_storage, $requested_value) {
  $section_storage = array_shift($section_storage);
  $contexts = $section_storage
    ->getContexts();
  // Provide a fallback view mode; this will be overridden by specific
  // contexts, below. We need a fallback since some entity types (such as
  // Layout entities) do not implement a view mode.
  $view_mode = 'default';
  if ($requested_value == 'contexts') {
    return $contexts;
  }
  if ($section_storage instanceof OverridesSectionStorageInterface) {
    $entity = $contexts['entity']
      ->getContextValue();
    $view_mode = $contexts['view_mode']
      ->getContextValue();
    $entity_type = $entity
      ->getEntityTypeId();
    $bundle = $entity
      ->bundle();
  }
  elseif (isset($contexts['entity']) && $contexts['entity']
    ->getContextValue() instanceof ConfigEntityBase) {
    $entity = $view_display = $contexts['entity']
      ->getContextValue();
    $entity_type = $entity
      ->getEntityTypeId();
    $bundle = $entity
      ->bundle();
  }
  elseif (get_class($section_storage) == 'Drupal\\mini_layouts\\Plugin\\SectionStorage\\MiniLayoutSectionStorage') {
    $view_display = $contexts['display']
      ->getContextValue();
  }
  elseif (isset($contexts['display'])) {
    $entity = $contexts['display']
      ->getContextValue();
    $view_mode = $entity
      ->getMode();
    $bundle = $entity
      ->getTargetBundle();
    $entity_type = $entity
      ->getTargetEntityTypeId();
  }
  elseif (isset($contexts['layout'])) {
    $entity = $contexts['layout']
      ->getContextValue();
    $bundle = $entity
      ->getTargetBundle();
    $entity_type = $entity
      ->getTargetEntityType();
  }
  switch ($requested_value) {
    case 'entity':
      return $entity;
    case 'view_mode':
      return $view_mode;
    case 'bundle':
      return $bundle;
    case 'entity_type':
      return $entity_type;
  }
  $context = $entity_type . "." . $bundle . "." . $view_mode;
  $storage = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display');
  if ($requested_value == 'storage') {
    return $storage;
  }
  if (empty($view_display)) {
    $view_display = $storage
      ->load($context);
  }
  if ($requested_value == 'view_display') {
    return $view_display;
  }
  $third_party_settings = $view_display
    ->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction', []);
  if ($requested_value == 'third_party_settings') {
    return $third_party_settings;
  }
  return NULL;
}