You are here

class LayoutBuilderChooseBlockController in Panopoly Magic 8.2

Controller for choosing blocks in layout builder.

Hierarchy

Expanded class hierarchy of LayoutBuilderChooseBlockController

File

src/Controller/LayoutBuilderChooseBlockController.php, line 12

Namespace

Drupal\panopoly_magic\Controller
View 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

Namesort descending Modifiers Type Description Overrides
AjaxHelperTrait::getRequestWrapperFormat protected function Gets the wrapper format of the current request.
AjaxHelperTrait::isAjax protected function Determines if the current request is via AJAX.
ChooseBlockController::$blockManager protected property The block manager.
ChooseBlockController::$currentUser protected property The current user.
ChooseBlockController::$entityTypeManager protected property The entity type manager.
ChooseBlockController::build public function Provides the UI for choosing a new block.
ChooseBlockController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
ChooseBlockController::getAjaxAttributes protected function Get dialog attributes if an ajax request.
ChooseBlockController::inlineBlockList public function Provides the UI for choosing a new inline block.
ChooseBlockController::__construct public function ChooseBlockController constructor.
LayoutBuilderChooseBlockController::getBlockLinks protected function Overrides the parent to show a preview of the block, along with the link. Overrides ChooseBlockController::getBlockLinks
LayoutBuilderContextTrait::$contextRepository protected property The context repository.
LayoutBuilderContextTrait::contextRepository protected function Gets the context repository service.
LayoutBuilderContextTrait::getAvailableContexts protected function Provides all available contexts, both global and section_storage-specific.
LayoutBuilderHighlightTrait::blockAddHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutBuilderHighlightTrait::blockUpdateHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutBuilderHighlightTrait::sectionAddHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
LayoutBuilderHighlightTrait::sectionUpdateHighlightId protected function Provides the ID used to highlight the active Layout Builder UI element.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.