You are here

protected function LayoutBuilderBrowserEventSubscriber::getLibrarySectionLinks in Gin Layout Builder 8.2

Gets a render array of section links.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.

int $delta: The region the section is going in.

Return value

array The section links render array.

1 call to LayoutBuilderBrowserEventSubscriber::getLibrarySectionLinks()
LayoutBuilderBrowserEventSubscriber::onView in modules/wingsuit_lb/src/EventSubscriber/LayoutBuilderBrowserEventSubscriber.php
Add layout-builder-browser class layout_builder.choose_block build block.

File

modules/wingsuit_lb/src/EventSubscriber/LayoutBuilderBrowserEventSubscriber.php, line 131

Class

LayoutBuilderBrowserEventSubscriber
Class LayoutBuilderBrowserEventSubscriber.

Namespace

Drupal\wingsuit_lb\EventSubscriber

Code

protected function getLibrarySectionLinks(SectionStorageInterface $section_storage, $delta) {
  $sections = SectionLibraryTemplate::loadMultiple();
  $links = [];
  foreach ($sections as $section_id => $section) {
    $attributes = $this
      ->getAjaxAttributes();
    $attributes['class'][] = 'js-layout-builder-section-library-link';
    $attributes['class'][] = 'ws-lb-link';

    // Default library image.
    $img_path = drupal_get_path('module', 'section_library') . '/images/default.png';
    if ($fid = $section
      ->get('image')->target_id) {
      $file = File::load($fid);
      $img_path = $file
        ->getFileUri();
    }
    $icon_url = file_url_transform_relative(file_create_url($img_path));
    $link = [
      '#type' => 'link',
      '#title' => Markup::create('<div class="ws-lb__icon"><img src="' . $icon_url . '" class="section-library-link-img" /> </div>' . '<div class="ws-lb-link__label">' . $section
        ->label() . '</div>'),
      '#url' => Url::fromRoute('section_library.import_section_from_library', [
        'section_library_id' => $section_id,
        'section_storage_type' => $section_storage
          ->getStorageType(),
        'section_storage' => $section_storage
          ->getStorageId(),
        'delta' => $delta,
      ]),
      '#attributes' => $attributes,
    ];
    $links[] = $link;
  }
  return $links;
}