Deprecated code cleanup: Updating EntityManager to EntityFieldManagerInterface EntityManager is deprecated so I am trying to update code for Drupal 9. The documentation says it should usually be changed to EntityTypeManager, but in this case the code is using getFieldStorageDefinitions so it needs to be EntityFieldManagerInterface.

I changed this line:

  $fields = \Drupal::entityManager()-&gt;getFieldStorageDefinitions($entity_type);


To:

  $fields = \Drupal::EntityFieldManagerInterface()-&gt;getFieldStorageDefinitions($entity_type);


Which gives this error when I run behat:

  [error]  Error: Call to undefined method Drupal::EntityFieldManagerInterface() in _drush_behat_get_entity_field_types() (line 95 of /app/drush/Commands/contrib/behat-drush-endpoint/behat.inc) #0 /app/drush/Commands/contrib/behat-drush-endpoint/behat.inc(123): _drush_behat_get_entity_field_types('node')


However, I don't understand this error, because EntityFieldManagerInterface does have getFieldStorageDefinitions.

How can I update entityManager to EntityFieldManagerInterface?

Here's the full function if that's useful:

function _drush_behat_get_entity_field_types($entity_type) {
  $return = array();
  $fields = \Drupal::entityManager()-&gt;getFieldStorageDefinitions($entity_type);
  foreach ($fields as $field_name =&gt; $field) {
    if (_drush_behat_is_field($entity_type, $field_name)) {
      $return[$field_name] = $field-&gt;getType();
    }
  }
  return $return;
}
EntityFieldManager has no shortcut in \Drupal, so you need to get it through \Drupal::service():

$fields = \Drupal::service('entity_field.manager')-&gt;getFieldStorageDefinitions($entity_type);