You are here

protected function WebformEntityHandler::getEntityTypes in Webform Entity Handler 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/WebformHandler/WebformEntityHandler.php \Drupal\webform_entity_handler\Plugin\WebformHandler\WebformEntityHandler::getEntityTypes()

Prepare #options array for entity types.

Return value

array The prepared array of entities and bundles.

1 call to WebformEntityHandler::getEntityTypes()
WebformEntityHandler::buildConfigurationForm in src/Plugin/WebformHandler/WebformEntityHandler.php
Form constructor.

File

src/Plugin/WebformHandler/WebformEntityHandler.php, line 501

Class

WebformEntityHandler
Create or update an entity with a webform submission values.

Namespace

Drupal\webform_entity_handler\Plugin\WebformHandler

Code

protected function getEntityTypes() {
  $types = [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_id => $entity_type) {

    // Only allow content entities and ignore configuration entities.
    if ($entity_type instanceof ContentEntityTypeInterface) {
      if ($entity_type
        ->getBundleEntityType() !== NULL) {
        foreach ($this->entityTypeBundleInfo
          ->getBundleInfo($entity_id) as $bundle_id => $bundle_type) {
          $types[$entity_type
            ->getLabel()
            ->__toString()][$entity_id . ':' . $bundle_id] = $bundle_type['label'];
        }
      }
      else {
        $types[$entity_type
          ->getLabel()
          ->__toString()][$entity_id . ':' . $entity_id] = $entity_type
          ->getLabel();
      }
    }
  }

  // Sort by entity type id.
  $type_keys = array_keys($types);
  array_multisort($type_keys, SORT_NATURAL, $types);
  return $types;
}