-1

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()->getFieldStorageDefinitions($entity_type);

To:

  $fields = \Drupal::EntityFieldManagerInterface()->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()->getFieldStorageDefinitions($entity_type);
  foreach ($fields as $field_name => $field) {
    if (_drush_behat_is_field($entity_type, $field_name)) {
      $return[$field_name] = $field->getType();
    }
  }
  return $return;
}
  • EntityFieldManagerInterface()->getFieldStorageDefinitions 😱😬 clearly you need to learn what an interface is for 🙄 – No Sssweat Apr 30 at 10:42
1

EntityFieldManager has no shortcut in \Drupal, so you need to get it through \Drupal::service():

$fields = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type);
| improve this answer | |

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.