public function WebformEntityReferenceManager::getWebforms in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformEntityReferenceManager.php \Drupal\webform\WebformEntityReferenceManager::getWebforms()
Get an entity's target webform.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: A fieldable content entity.
Return value
array An array of webforms.
Overrides WebformEntityReferenceManagerInterface::getWebforms
2 calls to WebformEntityReferenceManager::getWebforms()
- WebformEntityReferenceManager::getUserWebformId in src/
WebformEntityReferenceManager.php - Get user specified webform for a source entity.
- WebformEntityReferenceManager::getWebform in src/
WebformEntityReferenceManager.php - Get an entity's target webform.
File
- src/
WebformEntityReferenceManager.php, line 230
Class
- WebformEntityReferenceManager
- Webform entity reference (field) manager.
Namespace
Drupal\webformCode
public function getWebforms(EntityInterface $entity = NULL) {
// Cache the source entity's webforms.
$entity_id = $entity
->getEntityTypeId() . '-' . $entity
->id();
if (isset($this->webforms[$entity_id])) {
return $this->webforms[$entity_id];
}
$target_entities = [];
$sorted_entities = [];
$field_names = $this
->getFieldNames($entity);
foreach ($field_names as $field_name) {
foreach ($entity->{$field_name} as $item) {
if ($item->entity) {
$sorted_entities[$item->target_id] = method_exists($item->entity, 'getWeight') ? $item->entity
->getWeight() : 0;
$target_entities[$item->target_id] = $item->entity;
}
}
}
// Add paragraphs check.
$this
->getParagraphWebformsRecursive($entity, $target_entities, $sorted_entities);
// Sort the webforms by key and then weight.
ksort($sorted_entities);
asort($sorted_entities, SORT_NUMERIC);
// Return the sort webforms.
$webforms = [];
foreach (array_keys($sorted_entities) as $target_id) {
$webforms[$target_id] = $target_entities[$target_id];
}
$this->webforms[$entity_id] = $webforms;
return $webforms;
}