You are here

public function WebformEntityReferenceManager::getFieldNames in Webform 8.5

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

Get an entity's webform field names.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A fieldable content entity.

Return value

array An array of webform fields associate with an entity.

Overrides WebformEntityReferenceManagerInterface::getFieldNames

3 calls to WebformEntityReferenceManager::getFieldNames()
WebformEntityReferenceManager::getFieldName in src/WebformEntityReferenceManager.php
Get an entity's webform field name.
WebformEntityReferenceManager::getParagraphWebformsRecursive in src/WebformEntityReferenceManager.php
Get webform associate with a paragraph field from entity.
WebformEntityReferenceManager::getWebforms in src/WebformEntityReferenceManager.php
Get an entity's target webform.

File

src/WebformEntityReferenceManager.php, line 184

Class

WebformEntityReferenceManager
Webform entity reference (field) manager.

Namespace

Drupal\webform

Code

public function getFieldNames(EntityInterface $entity = NULL) {
  if ($entity === NULL || !$entity instanceof FieldableEntityInterface) {
    return [];
  }

  // Cache the source entity's field names.
  $entity_id = $entity
    ->getEntityTypeId() . '-' . $entity
    ->id();
  if (isset($this->fieldNames[$entity_id])) {
    return $this->fieldNames[$entity_id];
  }
  $field_names = [];
  if ($entity instanceof ContentEntityInterface) {
    $fields = $entity
      ->getFieldDefinitions();
    foreach ($fields as $field_name => $field_definition) {
      if ($field_definition
        ->getType() === 'webform') {
        $field_names[$field_name] = $field_name;
      }
    }
  }

  // Sort fields alphabetically.
  ksort($field_names);
  $this->fieldNames[$entity_id] = $field_names;
  return $field_names;
}