You are here

public static function LayoutParagraphsWidget::findElementByUuid in Layout Paragraphs 1.0.x

Recursively search the build array for element with matching uuid.

Parameters

array $array: Nested build array.

string $uuid: The uuid of the element to find.

Return value

array The matching element build array.

1 call to LayoutParagraphsWidget::findElementByUuid()
LayoutParagraphsWidget::saveItemAjax in src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php
Ajax callback to return the entire ERL element.

File

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

Class

LayoutParagraphsWidget
Entity Reference with Layout field widget.

Namespace

Drupal\layout_paragraphs\Plugin\Field\FieldWidget

Code

public static function findElementByUuid(array $array, string $uuid) {
  $element = FALSE;
  if (isset($array['active_items']['items']) && isset($array['disabled']['items'])) {
    return static::findElementByUuid($array['active_items']['items'] + $array['disabled']['items'], $uuid);
  }
  foreach ($array as $key => $item) {
    if (is_array($item)) {
      if (isset($item['#entity'])) {
        if ($item['#entity']
          ->uuid() == $uuid) {
          return $item;
        }
      }
      if (isset($item['preview']['regions'])) {
        foreach (Element::children($item['preview']['regions']) as $region_name) {
          if ($element = static::findElementByUuid($item['preview']['regions'][$region_name], $uuid)) {
            return $element;
          }
        }
      }
    }
  }
  return $element;
}