You are here

protected function WebformEntityReferenceManager::getParagraphWebformsRecursive in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformEntityReferenceManager.php \Drupal\webform\WebformEntityReferenceManager::getParagraphWebformsRecursive()

Get webform associate with a paragraph field from entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: An entity.

array $target_entities: An associate array of targeted webfrom entities.

array $sorted_entities: An associate array of sorted webfrom entities by weight.

1 call to WebformEntityReferenceManager::getParagraphWebformsRecursive()
WebformEntityReferenceManager::getWebforms in src/WebformEntityReferenceManager.php
Get an entity's target webform.

File

src/WebformEntityReferenceManager.php, line 282

Class

WebformEntityReferenceManager
Webform entity reference (field) manager.

Namespace

Drupal\webform

Code

protected function getParagraphWebformsRecursive(EntityInterface $entity, array &$target_entities, array &$sorted_entities) {

  // Add paragraphs check.
  if (!$this->moduleHandler
    ->moduleExists('paragraphs')) {
    return;
  }

  // Make sure the entity exists and is fieldable.
  if ($entity === NULL || !$entity instanceof FieldableEntityInterface) {
    return;
  }
  $paragraph_fields = $this
    ->getParagraphFieldNames($entity);
  foreach ($paragraph_fields as $paragraph_field) {
    if (!$entity
      ->hasField($paragraph_field)) {
      continue;
    }
    foreach ($entity
      ->get($paragraph_field) as $paragraph_item) {
      $paragraph = $paragraph_item->entity;
      if ($paragraph) {
        $webform_field_names = $this
          ->getFieldNames($paragraph);
        foreach ($webform_field_names as $webform_field_name) {
          foreach ($paragraph->{$webform_field_name} as $webform_field_item) {
            if ($webform_field_item->entity) {
              $sorted_entities[$webform_field_item->target_id] = method_exists($webform_field_item->entity, 'getWeight') ? $webform_field_item->entity
                ->getWeight() : 0;
              $target_entities[$webform_field_item->target_id] = $webform_field_item->entity;
            }
          }
        }
        $this
          ->getParagraphWebformsRecursive($paragraph, $target_entities, $sorted_entities);
      }
    }
  }
}