class LayoutBuilderChooseBlockController in Panopoly 8.2
Controller for choosing blocks in layout builder.
Hierarchy
- class \Drupal\layout_builder\Controller\ChooseBlockController implements ContainerInjectionInterface uses AjaxHelperTrait, StringTranslationTrait, LayoutBuilderContextTrait, LayoutBuilderHighlightTrait
- class \Drupal\panopoly_magic\Controller\LayoutBuilderChooseBlockController
Expanded class hierarchy of LayoutBuilderChooseBlockController
File
- modules/
panopoly/ panopoly_magic/ src/ Controller/ LayoutBuilderChooseBlockController.php, line 12
Namespace
Drupal\panopoly_magic\ControllerView source
class LayoutBuilderChooseBlockController extends ChooseBlockController {
/**
* {@inheritDoc}
*
* Overrides the parent to show a preview of the block, along with the link.
*/
protected function getBlockLinks(SectionStorageInterface $section_storage, $delta, $region, array $blocks) {
$contexts = $this
->getAvailableContexts($section_storage);
$build = [
'#links' => [],
];
foreach ($blocks as $block_id => $block) {
$block_preview = [
'#theme' => 'panopoly_magic_preview',
'#title' => $block['admin_label'],
'#attached' => [
'library' => [
'panopoly_magic/preview',
],
],
];
// @todo Inject this
$block_preview['preview'] = \Drupal::service('panopoly_magic.block_preview_renderer')
->buildBlockPreview($block_id, $contexts);
$attributes = $this
->getAjaxAttributes();
$attributes['class'][] = 'js-layout-builder-block-link';
$block_preview['add_link'] = [
'#type' => 'link',
'#title' => $this
->t('Add<span class="visually-hidden"> @name</span>', [
'@name' => $block['admin_label'],
]),
'#url' => Url::fromRoute('layout_builder.add_block', [
'section_storage_type' => $section_storage
->getStorageType(),
'section_storage' => $section_storage
->getStorageId(),
'delta' => $delta,
'region' => $region,
'plugin_id' => $block_id,
]),
'#attributes' => $attributes,
];
$build[$block_id] = $block_preview;
}
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. | |
ChooseBlockController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ChooseBlockController:: |
protected | function | Get dialog attributes if an ajax request. | |
ChooseBlockController:: |
public | function | Provides the UI for choosing a new inline block. | |
ChooseBlockController:: |
public | function | ChooseBlockController constructor. | |
LayoutBuilderChooseBlockController:: |
protected | function |
Overrides the parent to show a preview of the block, along with the link. Overrides ChooseBlockController:: |
|
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. |