Drupal - How to get a list/array of all content entities?

This is what you need:

use Drupal\Core\Entity\ContentEntityType;

$content_entity_types = [];
$entity_type_definations = \Drupal::entityTypeManager()->getDefinitions();
/* @var $definition EntityTypeInterface */
foreach ($entity_type_definations as $definition) {
  if ($definition instanceof ContentEntityType) {
    $content_entity_types[] = $definition;
  }
}

But a better approach would be to get the field first and then the bundles which has this field. For example, we are looking for the "field_image" in "node" typed entities:

   use Drupal\field\FieldStorageConfig;

   $field_image = FieldStorageConfig::load('node.field_image') 
   $bundles = $field_image->getBundles();

Tags:

Entities

8