You are here

trait BlockVisibilityLister in Block Visibility Groups 8

Provides functionality to get block visibility conditions and labels.

Hierarchy

1 file declares its use of BlockVisibilityLister
BlockVisibilityGroupDeleteForm.php in src/Form/BlockVisibilityGroupDeleteForm.php

File

src/BlockVisibilityLister.php, line 11

Namespace

Drupal\block_visibility_groups
View source
trait BlockVisibilityLister {

  /**
   * Get labels for groups.
   *
   * @return array
   *   The list of labels.
   */
  protected function getBlockVisibilityLabels(EntityStorageInterface $storage) {
    $block_visibility_groups = $storage
      ->loadMultiple();
    $labels = [];
    foreach ($block_visibility_groups as $type) {
      $labels[$type
        ->id()] = $type
        ->label();
    }
    return $labels;
  }

  /**
   * Get the visibility group for a block.
   *
   * @param \Drupal\block\Entity\Block $block
   *   The block instance.
   *
   * @return string
   *   The config group name.
   */
  protected function getGroupForBlock(Block $block) {

    /** @var ConditionPluginCollection $conditions */
    $conditions = $block
      ->getVisibilityConditions();
    $config_block_visibility_group = '';
    if ($conditions
      ->has('condition_group')) {
      $condition_config = $conditions
        ->get('condition_group')
        ->getConfiguration();
      $config_block_visibility_group = $condition_config['block_visibility_group'];
      return $config_block_visibility_group;
    }
    return $config_block_visibility_group;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BlockVisibilityLister::getBlockVisibilityLabels protected function Get labels for groups.
BlockVisibilityLister::getGroupForBlock protected function Get the visibility group for a block.