You are here

public function LayoutParagraphsWidget::hasChildren in Layout Paragraphs 1.0.x

Search $items for children of $parent.

Parameters

\Drupal\Paragraphs\ParagraphInterface $parent: The parent paragraph.

array $items: An array of items to search.

string $region: The region string.

Return value

bool True if finds children.

2 calls to LayoutParagraphsWidget::hasChildren()
LayoutParagraphsWidget::entityForm in src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php
Builds an entity form for a paragraph item.
LayoutParagraphsWidget::removeForm in src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php
Builds the remove item confirmation form.

File

src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php, line 2069

Class

LayoutParagraphsWidget
Entity Reference with Layout field widget.

Namespace

Drupal\layout_paragraphs\Plugin\Field\FieldWidget

Code

public function hasChildren(ParagraphInterface $parent, array $items, string $region = '') {
  $uuid = $parent
    ->uuid();
  foreach ($items as $item) {
    if (isset($item['entity'])) {
      $layout_settings = $this
        ->getLayoutSettings($item['entity']);
      if ($region) {
        if ($layout_settings['region'] == $region && $layout_settings['parent_uuid'] == $uuid) {
          return TRUE;
        }
      }
      elseif ($layout_settings['parent_uuid'] == $uuid) {
        return TRUE;
      }
    }
  }
  return FALSE;
}