27

How to list all available entity types in Drupal using drush?

Related:

3 Answers 3

50

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.

5
  • 1
    For Drupal 8, drush eval "print_r(array_keys(\Drupal::entityTypeManager()->getDefinitions()));"
    – Jason
    Commented Oct 13, 2016 at 16:09
  • 2
    For me it has to be drush eval "print_r(array_keys(\Drupal::entityManager()->getDefinitions()))"; Commented Apr 4, 2017 at 17:50
  • use Cpas E instead of e in EntityManager. drush eval "print_r(array_keys(\Drupal::EntityManager()->getDefinitions‌​()))"; entityManager is depricated Commented Oct 12, 2017 at 6:04
  • 4
    entityManager is deprecated on latest versions of d8, use entityTypeManager for newer versions
    – wranvaud
    Commented Jul 29, 2019 at 17:25
  • If you want to list specifically content/config types use this: drush eval "print_r(\Drupal::entityTypeManager()->getDefinitions());" | grep ContentEntityType (or ConfigEntityType for config entities)
    – Hodgekins
    Commented Aug 13, 2022 at 9:44
15

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.

4
  • 2
    The OP says specifically "Using Drush" Commented May 3, 2018 at 15:45
  • 4
    drush eval 'system("drupal de");' 😉
    – diamondsea
    Commented Feb 26, 2019 at 18:09
  • Thanks @diamondsea 😉 Commented Apr 26, 2019 at 6:58
  • Added bonus with console is to see if it's a content or configuration entity.
    – wranvaud
    Commented Dec 13, 2021 at 15:10
5

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
1
  • 2
    Another downvoter that don't says what's the problem with the answer just hit the downvote button. But if you don't says what's the problem I can't fix it. Commented Apr 18, 2017 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.