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
- class \Drupal\layout_paragraphs\LayoutParagraphsComponent
- class \Drupal\layout_paragraphs\LayoutParagraphsSection
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_paragraphsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LayoutParagraphsComponent:: |
protected | property | The paragraph entity. | |
LayoutParagraphsComponent:: |
public | function | Returns the wrapped paragraph entity. | |
LayoutParagraphsComponent:: |
public | function | Returns the parent component if one exists. | |
LayoutParagraphsComponent:: |
public | function | Gets the region for the component. | |
LayoutParagraphsComponent:: |
public | function | Returns a single layout paragraph setting. | |
LayoutParagraphsComponent:: |
public | function | Returns the layout paragraph's behavior settings. | |
LayoutParagraphsComponent:: |
public | function | Returns true if this component has a layout applied. | |
LayoutParagraphsComponent:: |
public | function | Returns true if disabled. | |
LayoutParagraphsComponent:: |
public | function | Returns true if this component has a layout applied. | |
LayoutParagraphsComponent:: |
public static | function | Static wrapper for isLayout(). | |
LayoutParagraphsComponent:: |
public | function | A "root" component is rendered at the top level. | |
LayoutParagraphsComponent:: |
public static | function | Static wrapper for isRoot(). | |
LayoutParagraphsComponent:: |
public | function | Sets the layout paragraph's behavior settings. | |
LayoutParagraphsSection:: |
protected | property | An array of components. | |
LayoutParagraphsSection:: |
public | function |
Returns an array of default settings. Overrides LayoutParagraphsComponent:: |
|
LayoutParagraphsSection:: |
public | function | Wraps the paragraph is the correct component class. | |
LayoutParagraphsSection:: |
public | function | Returns the child component with matching uuid. | |
LayoutParagraphsSection:: |
public | function | Returns a list of all components for this collection. | |
LayoutParagraphsSection:: |
public | function | Get the components for a single region. | |
LayoutParagraphsSection:: |
public | function | Returns the layout plugin settings for the provided paragraph. | |
LayoutParagraphsSection:: |
public | function | Returns the layout plugin id. | |
LayoutParagraphsSection:: |
public | function |
Constructor. Overrides LayoutParagraphsComponent:: |