You are here

LayoutBuilderComponentRenderArray.php in Layout Builder Component Attributes 1.1.x

File

src/EventSubscriber/LayoutBuilderComponentRenderArray.php
View source
<?php

namespace Drupal\layout_builder_component_attributes\EventSubscriber;

use Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent;
use Drupal\layout_builder\LayoutBuilderEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Class LayoutBuilderComponentRenderArray.
 */
class LayoutBuilderComponentRenderArray implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = [
      'onBuildRender',
    ];
    return $events;
  }

  /**
   * Adds block classes to section component.
   *
   * @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event
   *   The section component render event.
   */
  public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
    $build = $event
      ->getBuild();
    if (!empty($build)) {
      $build['#component_attributes'] = $event
        ->getComponent()
        ->get('component_attributes');
      $event
        ->setBuild($build);
    }
  }

}

Classes

Namesort descending Description
LayoutBuilderComponentRenderArray Class LayoutBuilderComponentRenderArray.