Drupal - How to list all available entity types?

Drupal 7

drush eval "print_r(array_keys(entity_get_info()));"

Drupal 8

drush eval "print_r(array_keys(\Drupal::entityTypeManager()->getDefinitions()));"

as per Jason suggestion,

or:

drush eval "print_r(array_keys(\Drupal::entityManager()->getDefinitions()));"

as per @RaisinBranCrunch suggestion. Note \Drupal::entityManager() is being deprecated in 8.x.


Drupal 8

Use the drupal console command:

drupal debug:entity

or (short hand):

drupal de

This will produce a concise list of entities available in your instance.


You can create a drush command named entities-list. Create a module, put inside a file named drush_entity.drush.inc and paste this code:

<?php
/**
 * @file
 * Drush commands related to Entities.
 */

/**
* Implements hook_drush_command().
*/
function drush_entity_drush_command() {
  $items['entities-list'] = array(
    'description' => dt("Show a list of available entities."),
    'aliases' => array('el'),
  );
  return $items;
}

/**
 * Callback for the content-type-list command.
 */
function drush_drush_entity_entities_list() {
  $entities = array_keys(entity_get_info());
  sort($entities);

  drush_print(dt("Machine name"));
  drush_print(implode("\r\n", $entities));
}

Install the module, run drush cc drush to clear the drush cache and use the command like this:

drush el

or

drush entities-list

If you want add another alias to the command add elements to the aliases array like this:

'aliases' => array('el', 'another'),

And you can use this commands:

drush el
drush entities-list
drush another

Always the output will be:

Machine name:
entity 1
entity 2
entity...
entity n

EDIT:

There is another solution using the Drush Entity module:

drush entity-type-read

Tags:

Entities

Drush