15

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

Related:

27

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.

  • 1
    For Drupal 8, drush eval "print_r(array_keys(\Drupal::entityTypeManager()->getDefinitions()));" – Jason Oct 13 '16 at 16:09
  • 2
    For me it has to be drush eval "print_r(array_keys(\Drupal::entityManager()->getDefinitions()))"; – RaisinBranCrunch Apr 4 '17 at 17:50
  • use Cpas E instead of e in EntityManager. drush eval "print_r(array_keys(\Drupal::EntityManager()->getDefinitions‌​()))"; entityManager is depricated – Suresh Kumara Oct 12 '17 at 6:04
  • 1
    entityManager is deprecated on latest versions of d8, use entityTypeManager for newer versions – wranvaud Jul 29 at 17:25
4

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.

3

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
    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. – Adrian Cid Almaguer Apr 18 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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