class ChooseBlockController in Layout Builder Restrictions 8.2
Defines a controller to choose a new block.
@internal Controller classes are internal.
Hierarchy
- class \Drupal\layout_builder\Controller\ChooseBlockController implements ContainerInjectionInterface uses AjaxHelperTrait, StringTranslationTrait, LayoutBuilderContextTrait, LayoutBuilderHighlightTrait
- class \Drupal\layout_builder_restrictions\Controller\ChooseBlockController
Expanded class hierarchy of ChooseBlockController
File
- src/
Controller/ ChooseBlockController.php, line 14
Namespace
Drupal\layout_builder_restrictions\ControllerView source
class ChooseBlockController extends ChooseBlockControllerCore {
/**
* {@inheritdoc}
*/
public function build(SectionStorageInterface $section_storage, $delta, $region) {
$build = parent::build($section_storage, $delta, $region);
// Retrieve defined Layout Builder Restrictions plugins.
$layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
$restriction_plugins = $layout_builder_restrictions_manager
->getSortedPlugins();
foreach (array_keys($restriction_plugins) as $id) {
$plugin = $layout_builder_restrictions_manager
->createInstance($id);
$allowed_inline_blocks = $plugin
->inlineBlocksAllowedinContext($section_storage, $delta, $region);
// If no inline blocks are allowed, remove the "Create custom block" link.
if (empty($allowed_inline_blocks)) {
unset($build['add_block']);
}
}
return $build;
}
/**
* {@inheritdoc}
*/
public function inlineBlockList(SectionStorageInterface $section_storage, $delta, $region) {
$build = parent::inlineBlockList($section_storage, $delta, $region);
// Retrieve defined Layout Builder Restrictions plugins.
$layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
$restriction_plugins = $layout_builder_restrictions_manager
->getSortedPlugins();
foreach (array_keys($restriction_plugins) as $id) {
$plugin = $layout_builder_restrictions_manager
->createInstance($id);
$allowed_inline_blocks = $plugin
->inlineBlocksAllowedinContext($section_storage, $delta, $region);
// Loop through links and remove those for disallowed inline block types.
foreach ($build['links']['#links'] as $key => $link) {
$route_parameters = $link['url']
->getRouteParameters();
if (!in_array($route_parameters['plugin_id'], $allowed_inline_blocks)) {
unset($build['links']['#links'][$key]);
}
}
}
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxHelperTrait:: |
protected | function | Gets the wrapper format of the current request. | |
AjaxHelperTrait:: |
protected | function | Determines if the current request is via AJAX. | |
ChooseBlockController:: |
protected | property | The block manager. | |
ChooseBlockController:: |
protected | property | The current user. | |
ChooseBlockController:: |
protected | property | The entity type manager. | |
ChooseBlockController:: |
public | function |
Provides the UI for choosing a new block. Overrides ChooseBlockController:: |
|
ChooseBlockController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ChooseBlockController:: |
protected | function | Get dialog attributes if an ajax request. | |
ChooseBlockController:: |
protected | function | Gets a render array of block links. | |
ChooseBlockController:: |
public | function |
Provides the UI for choosing a new inline block. Overrides ChooseBlockController:: |
|
ChooseBlockController:: |
public | function | ChooseBlockController constructor. | |
LayoutBuilderContextTrait:: |
protected | property | The context repository. | |
LayoutBuilderContextTrait:: |
protected | function | Gets the context repository service. | |
LayoutBuilderContextTrait:: |
protected | function | Provides all available contexts, both global and section_storage-specific. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |