You are here

class LayoutParagraphsSection in Layout Paragraphs 2.0.x

Provides a domain object for a Layout Paragraphs Section.

A Layout Paragraphs Section is a Layout Paragraphs Component with a Layout applied.

See also:

Hierarchy

Expanded class hierarchy of LayoutParagraphsSection

2 files declare their use of LayoutParagraphsSection
LayoutParagraphsBehavior.php in src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php
LayoutParagraphsBuilder.php in src/Element/LayoutParagraphsBuilder.php

File

src/LayoutParagraphsSection.php, line 17

Namespace

Drupal\layout_paragraphs
View source
class LayoutParagraphsSection extends LayoutParagraphsComponent {

  /**
   * An array of components.
   *
   * @var \Drupal\layout_paragraphs\LayoutParagraphsComponent|LayoutParagraphsSection[]
   */
  protected $components;

  /**
   * Constructor.
   *
   * @param \Drupal\paragraphs\Entity\Paragraph $paragraph
   *   The paragraph this layout section is attached to.
   * @param \Drupal\layout_paragraphs\LayoutParagraphsComponent[] $components
   *   An array of child components.
   */
  public function __construct(Paragraph $paragraph, array $components = []) {
    parent::__construct($paragraph);
    $this->components = $components;
  }

  /**
   * Wraps the paragraph is the correct component class.
   *
   * @param Drupal\paragraphs\Entity\Paragraph $paragraph
   *   The paragraph entity.
   *
   * @return LayoutParagraphsComponent|LayoutParagraphsSection
   *   The component.
   */
  public function getComponent(Paragraph $paragraph) {
    foreach ($this->components as $component) {
      if ($component
        ->getEntity()
        ->uuid() == $paragraph
        ->uuid()) {
        return $component;
      }
    }
  }

  /**
   * Returns the child component with matching uuid.
   *
   * @param string $uuid
   *   The uuid to search for.
   *
   * @return LayoutParagraphsComponent
   *   The component.
   */
  public function getComponentByUuid($uuid) {
    foreach ($this
      ->getComponents() as $component) {
      if ($component
        ->getEntity()
        ->uuid() == $uuid) {
        return $component;
      }
    }
  }

  /**
   * Get the components for a single region.
   *
   * @param string $region
   *   The region name.
   *
   * @return Drupal\layout_paragraphs\LayoutParagraphsComponent[]
   *   An array of components.
   */
  public function getComponentsForRegion(string $region) {
    return array_filter($this
      ->getComponents(), function (LayoutParagraphsComponent $component) use ($region) {
      return $component
        ->getRegion() == $region;
    });
  }

  /**
   * Returns a list of all components for this collection.
   *
   * @return array
   *   An array of layout paragraph components.
   */
  public function getComponents() {
    return $this->components;
  }

  /**
   * Returns the layout plugin id.
   *
   * @return string
   *   The layout id.
   */
  public function getLayoutId() {
    $settings = $this
      ->getSettings();
    return $settings['layout'];
  }

  /**
   * Returns the layout plugin settings for the provided paragraph.
   *
   * @return array
   *   The settings array.
   */
  public function getLayoutConfiguration() {
    return $this
      ->getSettings()['config'] ?? [];
  }

  /**
   * {@inheritDoc}
   */
  public function defaultSettings() {
    return [
      'layout' => '',
      'config' => [],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayoutParagraphsComponent::$paragraph protected property The paragraph entity.
LayoutParagraphsComponent::getEntity public function Returns the wrapped paragraph entity.
LayoutParagraphsComponent::getParentUuid public function Returns the parent component if one exists.
LayoutParagraphsComponent::getRegion public function Gets the region for the component.
LayoutParagraphsComponent::getSetting public function Returns a single layout paragraph setting.
LayoutParagraphsComponent::getSettings public function Returns the layout paragraph's behavior settings.
LayoutParagraphsComponent::hasLayout public function Returns true if this component has a layout applied.
LayoutParagraphsComponent::isDisabled public function Returns true if disabled.
LayoutParagraphsComponent::isLayout public function Returns true if this component has a layout applied.
LayoutParagraphsComponent::isLayoutComponent public static function Static wrapper for isLayout().
LayoutParagraphsComponent::isRoot public function A "root" component is rendered at the top level.
LayoutParagraphsComponent::isRootComponent public static function Static wrapper for isRoot().
LayoutParagraphsComponent::setSettings public function Sets the layout paragraph's behavior settings.
LayoutParagraphsSection::$components protected property An array of components.
LayoutParagraphsSection::defaultSettings public function Returns an array of default settings. Overrides LayoutParagraphsComponent::defaultSettings
LayoutParagraphsSection::getComponent public function Wraps the paragraph is the correct component class.
LayoutParagraphsSection::getComponentByUuid public function Returns the child component with matching uuid.
LayoutParagraphsSection::getComponents public function Returns a list of all components for this collection.
LayoutParagraphsSection::getComponentsForRegion public function Get the components for a single region.
LayoutParagraphsSection::getLayoutConfiguration public function Returns the layout plugin settings for the provided paragraph.
LayoutParagraphsSection::getLayoutId public function Returns the layout plugin id.
LayoutParagraphsSection::__construct public function Constructor. Overrides LayoutParagraphsComponent::__construct