如何列出所有可用的实体类型?


Answers:


29

Drupal 7

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

Drupal 8

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

根据杰森的建议

要么:

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

根据@ RaisinBranCrunch建议。Note \Drupal::entityManager()在8.x中已弃用。


1
对于Drupal 8,请尝试评估“ print_r(array_keys(\ Drupal :: entityTypeManager()-> getDefinitions()));”
杰森

2
对我来说必须是drush eval "print_r(array_keys(\Drupal::entityManager()->getDefinitions()))";
RaisinBranCrunch '17

在EntityManager中使用Cpas E代替e。drush eval“ print_r(array_keys(\ Drupal :: EntityManager()-> getDefinitions‌(())))”; 实体管理员简报
Suresh Kumara

1
entityManager在d8的最新版本上已弃用,而在entityTypeManager较新的版本上使用
wranvaud


3

您可以创建一个名为的drush命令entities-list。创建一个模块,放入一个名为的文件中,drush_entity.drush.inc并粘贴以下代码:

<?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));
}

安装该模块,运行drush cc drush以清除刷新缓存并使用如下命令:

drush el

要么

drush entities-list

如果要向命令添加另一个别名,则将元素添加到别名数组中,如下所示:

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

您可以使用以下命令:

drush el
drush entities-list
drush another

输出始终为:

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

编辑:

还有另一个使用Drush Entity模块的解决方案:

drush entity-type-read

1
另一个没有说答案有什么问题的下降投票者,只需按下下降投票按钮。但是,如果您不说是什么问题,我将无法解决。
Adrian Cid Almaguer
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.