trait BlockVisibilityLister in Block Visibility Groups 8
Provides functionality to get block visibility conditions and labels.
Hierarchy
- trait \Drupal\block_visibility_groups\BlockVisibilityLister
1 file declares its use of BlockVisibilityLister
File
- src/
BlockVisibilityLister.php, line 11
Namespace
Drupal\block_visibility_groupsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockVisibilityLister:: |
protected | function | Get labels for groups. | |
BlockVisibilityLister:: |
protected | function | Get the visibility group for a block. |