Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Drupal 7

$allEntities = entity_get_info();
$nodeEntity = entity_get_info('node');

Drupal 8

/**
 * Gets the entity definition for an entity type.
 *
 * @param string|null $entity_type
 *   (optional) The entity type (e.g. 'node'). Leave NULL to retrieve
 *   information for all entity types.
 *
 * @return array
 *   An array containing the entity type's definition, as retrieved with
 *   \Drupal\Core\Entity\EntityManagerInterface. If $entity_type is NULL, an
 *   associative array of all entity type definitions keyed by entity type is
 *   returned.
 *
 * @see \Drupal\Core\Entity\EntityManagerInterface
 * @see hook_entity_info_alter()
 */

$allEntities = \Drupal::entityTypeManager()->getDefinitions();
$nodeEntity = \Drupal::entityTypeManager()->getDefinition('node');
Impacts: 
Module developers

Comments

agentrickard’s picture

Is there an issue for this, because I still see the wrapper function in entity.inc. And, fwiw, I despise this change.

podarok’s picture

I didn`t find issue yet, possibly this needs @todo )
The entity_get_info() marked as deprecated in sources but there were no any change-records before this one

---------------
Andrii Podanenko
CEO, ITCare

podarok’s picture

fixed )

---------------
Andrii Podanenko
CEO, ITCare

agentrickard’s picture

[edit]

I read the issue, and there is nothing relevant to marking this function as deprecated. I don't understand this change notice. Removing entity_get_info() in this manner is horrible DX. You are ripping out an API function for an obscure chained method.

Why would we do that? We didn't deprecate entity_create().

podarok’s picture

---------------
Andrii Podanenko
CEO, ITCare

clemens.tolboom’s picture

Use code like

      $exporter = new \SebastianBergmann\Exporter\Exporter();
      foreach(\Drupal::entityManager()->getDefinitions() as $id => $definition) {
        if (is_a($definition ,'Drupal\Core\Entity\ContentEntityType')) {
          $entities_info[$id] = $exporter->toArray($definition);
        }
      }

(See discussion in #2304863: EntityType should support toArray())

ttamniwdoog’s picture

If you want to output a list of entities in D8 with Drush try: drush ev "print_r(array_keys(\Drupal::entityTypeManager()->getDefinitions()));"
Or a specific entity's definition like moderation_state, try: drush ev "print_r(\Drupal::entityTypeManager()->getDefinition('moderation_state'));