You are here

protected function Entity::getEntityTypeOptions in Entity Embed 8

Builds a list of entity type options.

Configuration entity types without a view builder are filtered out while all other entity types are kept.

Return value

array An array of entity type labels, keyed by entity type name.

1 call to Entity::getEntityTypeOptions()
Entity::buildConfigurationForm in src/Plugin/EmbedType/Entity.php
Form constructor.

File

src/Plugin/EmbedType/Entity.php, line 227

Class

Entity
Entity embed type.

Namespace

Drupal\entity_embed\Plugin\EmbedType

Code

protected function getEntityTypeOptions() {
  $options = $this->entityTypeRepository
    ->getEntityTypeLabels(TRUE);
  foreach ($options as $group => $group_types) {
    foreach (array_keys($group_types) as $entity_type_id) {

      // Filter out entity types that do not have a view builder class.
      if (!$this->entityTypeManager
        ->getDefinition($entity_type_id)
        ->hasViewBuilderClass()) {
        unset($options[$group][$entity_type_id]);
      }
      elseif (!$this->entityTypeManager
        ->getDefinition($entity_type_id)
        ->hasKey('uuid')) {
        unset($options[$group][$entity_type_id]);
      }
      elseif (!$this->displayPluginManager
        ->getDefinitionOptionsForEntityType($entity_type_id)) {
        unset($options[$group][$entity_type_id]);
      }
    }
  }
  return $options;
}