You are here

function _layout_paragraphs_get_paragraphs in Layout Paragraphs 2.0.x

Returns a list of all sibling paragraphs given a single paragraph.

The returned list contains all of the referenced entities, including the passed $paragraph.

Parameters

\Drupal\paragraphs\Entity\Paragraph $paragraph: The paragraph to use for finding the complete list of siblings.

Return value

\Drupal\Core\Field\EntityReferenceFieldItemList The list of paragraphs.

1 call to _layout_paragraphs_get_paragraphs()
layout_paragraphs_paragraph_presave in ./layout_paragraphs.module
Implements hook_ENTITY_presave().

File

./layout_paragraphs.module, line 196
Contains layout_paragraphs.module.

Code

function _layout_paragraphs_get_paragraphs(Paragraph $paragraph) {
  $host = $paragraph
    ->getParentEntity();
  $parent_field = $paragraph
    ->get('parent_field_name');
  $field_name = $parent_field
    ->first()
    ->getString();

  /** @var \Drupal\Core\Field\EntityReferenceFieldItemList $item_list */
  $item_list = $host
    ->get($field_name);
  return $item_list
    ->referencedEntities();
}