You are here

public function EntityViewModeRestriction::inlineBlocksAllowedinContext in Layout Builder Restrictions 8.2

Returns an array of allowed inline blocks in a given context.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.

int $delta: The delta of the section to splice.

string $region: The region the block is going in.

Return value

array An array of allowed inline block types.

Overrides LayoutBuilderRestrictionBase::inlineBlocksAllowedinContext

File

src/Plugin/LayoutBuilderRestriction/EntityViewModeRestriction.php, line 277

Class

EntityViewModeRestriction
Controls behavior of the per-view mode plugin.

Namespace

Drupal\layout_builder_restrictions\Plugin\LayoutBuilderRestriction

Code

public function inlineBlocksAllowedinContext(SectionStorageInterface $section_storage, $delta, $region) {
  $view_display = $this
    ->getValuefromSectionStorage([
    $section_storage,
  ], 'view_display');
  $third_party_settings = $view_display
    ->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction', []);
  $whitelisted_blocks = isset($third_party_settings['whitelisted_blocks']) ? $third_party_settings['whitelisted_blocks'] : [];
  $blacklisted_blocks = isset($third_party_settings['blacklisted_blocks']) ? $third_party_settings['blacklisted_blocks'] : [];
  $restricted_categories = isset($third_party_settings['restricted_categories']) ? $third_party_settings['restricted_categories'] : [];
  if (in_array('Inline blocks', $restricted_categories)) {

    // All inline blocks have been restricted.
    return [];
  }
  elseif (isset($whitelisted_blocks['Inline blocks'])) {
    return $whitelisted_blocks['Inline blocks'];
  }
  else {
    $inline_blocks = $this
      ->getInlineBlockPlugins();
    if (isset($blacklisted_blocks['Inline blocks'])) {
      foreach ($inline_blocks as $key => $block) {

        // Unset explicitly blacklisted inline blocks.
        if (in_array($block, $blacklisted_blocks['Inline blocks'])) {
          unset($inline_blocks[$key]);
        }
      }
    }
    return $inline_blocks;
  }
}