Issue #3035953 by Berdir, andypost, vacho: Add @trigger_error() to deprecated EntityManager->EntityFieldManager methods

merge-requests/1119/head
Lee Rowlands 2019-04-26 17:09:28 +10:00
parent da94d7fc6b
commit a98b58765d
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
63 changed files with 394 additions and 231 deletions

View File

@ -212,7 +212,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
}
// Hide extra fields.
$extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = \Drupal::service('entity_field.manager')->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = isset($extra_fields['form']) ? $extra_fields['form'] : [];
foreach ($extra_fields as $extra_field => $info) {
if (!$this->getComponent($extra_field)) {

View File

@ -33,10 +33,10 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
* in state allows to avoid this and ensures that the various steps of the
* update process are predictable and repeatable.
*
* @see \Drupal\Core\Entity\EntityManagerInterface::getDefinition()
* @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledDefinition()
* @see \Drupal\Core\Entity\EntityManagerInterface::getFieldStorageDefinitions()
* @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledFieldStorageDefinitions()
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinition()
* @see \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition()
* @see \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions()
* @see \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions()
* @see hook_update_N()
*/
interface EntityDefinitionUpdateManagerInterface {

View File

@ -157,7 +157,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
$default_region = $this->getDefaultRegion();
// Fill in defaults for extra fields.
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
$extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = \Drupal::service('entity_field.manager')->getExtraFields($this->targetEntityType, $this->bundle);
$extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : [];
foreach ($extra_fields as $name => $definition) {
if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
@ -424,7 +424,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
*/
protected function getFieldDefinitions() {
if (!isset($this->fieldDefinitions)) {
$definitions = \Drupal::entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle);
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
// For "official" view modes and form modes, ignore fields whose
// definition states they should not be displayed.
if ($this->mode !== static::CUSTOM_MODE) {

View File

@ -96,7 +96,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
/**
@ -104,7 +104,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*/
public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities);
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
/**

View File

@ -508,12 +508,13 @@ class EntityFieldManager implements EntityFieldManagerInterface {
// In the second step, the per-bundle fields are added, based on the
// persistent bundle field map stored in a key value collection. This
// data is managed in the EntityManager::onFieldDefinitionCreate()
// and EntityManager::onFieldDefinitionDelete() methods. Rebuilding this
// information in the same way as base fields would not scale, as the
// time to query would grow exponentially with more fields and bundles.
// A cache would be deleted during cache clears, which is the only time
// it is needed, so a key value collection is used.
// data is managed in the
// FieldDefinitionListener::onFieldDefinitionCreate() and
// FieldDefinitionListener::onFieldDefinitionDelete() methods.
// Rebuilding this information in the same way as base fields would not
// scale, as the time to query would grow exponentially with more fields
// and bundles. A cache would be deleted during cache clears, which is
// the only time it is needed, so a key value collection is used.
$bundle_field_maps = $this->keyValueFactory->get('entity.definitions.bundle_field_map')->getAll();
foreach ($bundle_field_maps as $entity_type_id => $bundle_field_map) {
foreach ($bundle_field_map as $field_name => $map_entry) {

View File

@ -180,6 +180,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
* @see https://www.drupal.org/node/2549139
*/
public function getBaseFieldDefinitions($entity_type_id) {
@trigger_error('EntityManagerInterface::getBaseFieldDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getBaseFieldDefinitions() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
}
@ -193,19 +194,21 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
* @see https://www.drupal.org/node/2549139
*/
public function getFieldDefinitions($entity_type_id, $bundle) {
@trigger_error('EntityManagerInterface::getFieldDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getFieldStorageDefinitions($entity_type_id) {
@trigger_error('EntityManagerInterface::getFieldStorageDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
}
@ -226,53 +229,56 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityFieldManagerInterface::setFieldMap()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function setFieldMap(array $field_map) {
@trigger_error('EntityManagerInterface::setFieldMap() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::setFieldMap() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->setFieldMap($field_map);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMap()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getFieldMap() {
@trigger_error('EntityManagerInterface::getFieldMap() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMap() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->getFieldMap();
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMapByFieldType()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getFieldMapByFieldType($field_type) {
@trigger_error('EntityManagerInterface::getFieldMapByFieldType() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMapByFieldType() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->getFieldMapByFieldType($field_type);
}
/**
* {@inheritdoc}
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) {
@trigger_error('EntityManagerInterface::onFieldDefinitionCreate() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
@trigger_error('EntityManagerInterface::onFieldDefinitionCreate() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('field_definition.listener')->onFieldDefinitionCreate($field_definition);
}
@ -314,6 +320,7 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
* @see https://www.drupal.org/node/2549139
*/
public function clearCachedFieldDefinitions() {
@trigger_error('EntityManagerInterface::clearCachedFieldDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::clearCachedFieldDefinitions() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
}
@ -361,8 +368,15 @@ class EntityManager implements EntityManagerInterface, ContainerAwareInterface {
/**
* {@inheritdoc}
*
* @deprecated in drupal:8.0.0, will be removed before drupal:9.0.0.
* Use \Drupal\Core\Entity\EntityFieldManagerInterface::getExtraFields()
* instead.
*
* @see https://www.drupal.org/node/2549139
*/
public function getExtraFields($entity_type_id, $bundle) {
@trigger_error('EntityManagerInterface::getExtraFields() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getExtraFields() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity_field.manager')->getExtraFields($entity_type_id, $bundle);
}

View File

@ -79,10 +79,10 @@ class EntityDataDefinition extends ComplexDataDefinitionBase implements EntityDa
// See https://www.drupal.org/node/2169813.
$bundles = $this->getBundles();
if (is_array($bundles) && count($bundles) == 1) {
$this->propertyDefinitions = \Drupal::entityManager()->getFieldDefinitions($entity_type_id, reset($bundles));
$this->propertyDefinitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, reset($bundles));
}
else {
$this->propertyDefinitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type_id);
$this->propertyDefinitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
}
}
}

View File

@ -232,9 +232,11 @@ class ModuleInstaller implements ModuleInstallerInterface {
// handler can use this as an opportunity to create the necessary
// database tables.
// @todo Clean this up in https://www.drupal.org/node/2350111.
$entity_manager = \Drupal::entityManager();
$entity_type_manager = \Drupal::entityTypeManager();
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($entity_manager->getDefinitions() as $entity_type) {
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
foreach ($entity_type_manager->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == $module) {
$update_manager->installEntityType($entity_type);
}
@ -242,7 +244,7 @@ class ModuleInstaller implements ModuleInstallerInterface {
// The module being installed may be adding new fields to existing
// entity types. Field definitions for any entity type defined by
// the module are handled in the if branch.
foreach ($entity_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
if ($storage_definition->getProvider() == $module) {
// If the module being installed is also defining a storage key
// for the entity type, the entity schema may not exist yet. It
@ -390,9 +392,9 @@ class ModuleInstaller implements ModuleInstallerInterface {
// Clean up all entity bundles (including fields) of every entity type
// provided by the module that is being uninstalled.
// @todo Clean this up in https://www.drupal.org/node/2350111.
$entity_manager = \Drupal::entityManager();
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_type_bundle_info->getBundleInfo($entity_type_id)) as $bundle) {
\Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
@ -419,7 +421,9 @@ class ModuleInstaller implements ModuleInstallerInterface {
// opportunity to drop the corresponding database tables.
// @todo Clean this up in https://www.drupal.org/node/2350111.
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach ($entity_manager->getDefinitions() as $entity_type) {
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
foreach ($entity_type_manager->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == $module) {
$update_manager->uninstallEntityType($entity_type);
}
@ -427,7 +431,7 @@ class ModuleInstaller implements ModuleInstallerInterface {
// The module being uninstalled might have added new fields to
// existing entity types. This will add them to the deleted fields
// repository so their data will be purged on cron.
foreach ($entity_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
if ($storage_definition->getProvider() == $module) {
$update_manager->uninstallFieldStorageDefinition($storage_definition);
}

View File

@ -67,7 +67,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
$block_type = BlockContentType::load('foo');
$this->assertTrue($block_type, 'The new block type has been created.');
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'foo');
$this->assertTrue(isset($field_definitions['body']), 'Body field created when using the UI to create block content types.');
// Check that the block type was created in site default language.
@ -76,11 +76,11 @@ class BlockContentTypeTest extends BlockContentTestBase {
// Create block types programmatically.
$this->createBlockContentType('basic', TRUE);
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'basic');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'basic');
$this->assertTrue(isset($field_definitions['body']), "Body field for 'basic' block type created when using the testing API to create block content types.");
$this->createBlockContentType('other');
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'other');
$this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types.");
$block_type = BlockContentType::load('other');
@ -102,7 +102,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
// We need two block types to prevent /block/add redirecting.
$this->createBlockContentType('other');
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('block_content', 'other');
$this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
// Verify that title and body fields are displayed.
@ -124,7 +124,7 @@ class BlockContentTypeTest extends BlockContentTestBase {
'admin/structure/block/block-content' => 'Custom block library',
'admin/structure/block/block-content/manage/basic' => 'Edit Bar',
]);
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$this->drupalGet('block/add');
$this->assertRaw('Bar', 'New name was displayed.');

View File

@ -418,7 +418,7 @@ function _comment_entity_uses_integer_id($entity_type_id) {
if ($entity_type_id_key === FALSE) {
return FALSE;
}
$field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type->id());
$field_definitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type->id());
$entity_type_id_definition = $field_definitions[$entity_type_id_key];
return $entity_type_id_definition->getType() === 'integer';
}

View File

@ -31,8 +31,6 @@ interface CommentManagerInterface {
* - type: The field type.
* - bundles: The bundles in which the field appears, as an array with entity
* types as keys and the array of bundle names as values.
*
* @see \Drupal\Core\Entity\EntityManagerInterface::getFieldMap()
*/
public function getFields($entity_type_id);

View File

@ -2,7 +2,7 @@
namespace Drupal\comment\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\State\StateInterface;
@ -47,15 +47,15 @@ class EntityComment extends EntityContentBase {
* The storage for this entity type.
* @param array $bundles
* The list of bundles this entity type has.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager service.
* @param \Drupal\Core\State\StateInterface $state
* The state storage object.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_field_manager, $field_type_manager);
$this->state = $state;
}
@ -69,9 +69,9 @@ class EntityComment extends EntityContentBase {
$plugin_id,
$plugin_definition,
$migration,
$container->get('entity.manager')->getStorage($entity_type),
$container->get('entity_type.manager')->getStorage($entity_type),
array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
$container->get('entity.manager'),
$container->get('entity_field.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('state')
);

View File

@ -166,8 +166,8 @@ class NodeNewComments extends NumericField {
// reference, we arbitrarily use the first such field name we find.
// @todo Provide a means for selecting the comment field.
// https://www.drupal.org/node/2594201
$entity_manager = \Drupal::entityManager();
$field_map = $entity_manager->getFieldMapByFieldType('comment');
$entity_type_manager = \Drupal::entityTypeManager();
$field_map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('comment');
$comment_field_name = 'comment';
foreach ($field_map['node'] as $field_name => $field_data) {
foreach ($field_data['bundles'] as $bundle_name) {
@ -177,7 +177,7 @@ class NodeNewComments extends NumericField {
}
}
}
$page_number = $entity_manager->getStorage('comment')
$page_number = $entity_type_manager->getStorage('comment')
->getNewCommentPageNumber($this->getValue($values, 'comment_count'), $this->getValue($values), $node, $comment_field_name);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['url'] = $node->toUrl();

View File

@ -34,10 +34,12 @@ trait CommentTestTrait {
* Defaults to 'full'.
*/
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment', $comment_view_mode = 'full') {
$entity_manager = \Drupal::entityManager();
$entity_type_manager = \Drupal::entityTypeManager();
$entity_display_repository = \Drupal::service('entity_display.repository');
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
// Create the comment type if needed.
$comment_type_storage = $entity_manager->getStorage('comment_type');
$comment_type_storage = $entity_type_manager->getStorage('comment_type');
if ($comment_type = $comment_type_storage->load($comment_type_id)) {
if ($comment_type->getTargetEntityTypeId() !== $entity_type) {
throw new \InvalidArgumentException("The given comment type id $comment_type_id can only be used with the $entity_type entity type");
@ -56,8 +58,8 @@ trait CommentTestTrait {
// Add a comment field to the host entity type. Create the field storage if
// needed.
if (!array_key_exists($field_name, $entity_manager->getFieldStorageDefinitions($entity_type))) {
$entity_manager->getStorage('field_storage_config')->create([
if (!array_key_exists($field_name, $entity_field_manager->getFieldStorageDefinitions($entity_type))) {
$entity_type_manager->getStorage('field_storage_config')->create([
'entity_type' => $entity_type,
'field_name' => $field_name,
'type' => 'comment',
@ -68,8 +70,8 @@ trait CommentTestTrait {
])->save();
}
// Create the field if needed, and configure its form and view displays.
if (!array_key_exists($field_name, $entity_manager->getFieldDefinitions($entity_type, $bundle))) {
$entity_manager->getStorage('field_config')->create([
if (!array_key_exists($field_name, $entity_field_manager->getFieldDefinitions($entity_type, $bundle))) {
$entity_type_manager->getStorage('field_config')->create([
'label' => 'Comments',
'description' => '',
'field_name' => $field_name,

View File

@ -95,11 +95,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$form['#attached']['library'][] = 'content_translation/drupal.content_translation.admin';
$entity_manager = Drupal::entityManager();
$entity_type_manager = \Drupal::entityTypeManager();
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
$bundle_info_service = \Drupal::service('entity_type.bundle.info');
foreach ($form['#labels'] as $entity_type_id => $label) {
$entity_type = $entity_manager->getDefinition($entity_type_id);
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : [];
$entity_type = $entity_type_manager->getDefinition($entity_type_id);
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_field_manager->getFieldStorageDefinitions($entity_type_id) : [];
$entity_type_translatable = $content_translation_manager->isSupported($entity_type_id);
foreach ($bundle_info_service->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
@ -133,7 +135,7 @@ function _content_translation_form_language_content_settings_form_alter(array &$
];
}
$fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle);
$fields = $entity_field_manager->getFieldDefinitions($entity_type_id, $bundle);
if ($fields) {
foreach ($fields as $field_name => $definition) {
if ($definition->isComputed() || (!empty($storage_definitions[$field_name]) && _content_translation_is_field_translatability_configurable($entity_type, $storage_definitions[$field_name]))) {
@ -351,7 +353,7 @@ function content_translation_form_language_content_settings_submit(array $form,
// all of its fields will be not translatable.
foreach ($settings as $entity_type_id => &$entity_settings) {
foreach ($entity_settings as $bundle => &$bundle_settings) {
$fields = \Drupal::entityManager()->getFieldDefinitions($entity_type_id, $bundle);
$fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
if (!empty($bundle_settings['translatable'])) {
$bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type_id];
}

View File

@ -42,8 +42,7 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
*/
public function testSkipUntranslatable() {
$this->drupalLogin($this->translator);
$entity_manager = \Drupal::entityManager();
$fields = $entity_manager->getFieldDefinitions($this->entityTypeId, $this->bundle);
$fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityTypeId, $this->bundle);
// Turn off translatability for the metadata fields on the current bundle.
$metadata_fields = ['created', 'changed', 'uid', 'status'];
@ -57,7 +56,7 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
// Create a new test entity with original values in the default language.
$default_langcode = $this->langcodes[0];
$entity_id = $this->createEntity(['title' => $this->randomString()], $default_langcode);
$storage = $entity_manager->getStorage($this->entityTypeId);
$storage = \Drupal::entityTypeManager()->getStorage($this->entityTypeId);
$storage->resetCache();
$entity = $storage->load($entity_id);
@ -99,8 +98,7 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
*/
public function testSetTranslatable() {
$this->drupalLogin($this->translator);
$entity_manager = \Drupal::entityManager();
$fields = $entity_manager->getFieldDefinitions($this->entityTypeId, $this->bundle);
$fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityTypeId, $this->bundle);
// Turn off translatability for the metadata fields on the current bundle.
$metadata_fields = ['created', 'changed', 'uid', 'status'];
@ -114,7 +112,7 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
// Create a new test entity with original values in the default language.
$default_langcode = $this->langcodes[0];
$entity_id = $this->createEntity(['title' => $this->randomString(), 'status' => FALSE], $default_langcode);
$storage = $entity_manager->getStorage($this->entityTypeId);
$storage = \Drupal::entityTypeManager()->getStorage($this->entityTypeId);
$storage->resetCache();
$entity = $storage->load($entity_id);

View File

@ -103,14 +103,15 @@ class ContentTranslationSettingsTest extends BrowserTestBase {
'settings[comment][comment][fields][subject]' => FALSE,
];
$this->assertSettings('comment', 'comment_article', TRUE, $edit);
$definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['comment_body'];
$entity_field_manager = \Drupal::service('entity_field.manager');
$definition = $entity_field_manager->getFieldDefinitions('comment', 'comment_article')['comment_body'];
$this->assertTrue($definition->isTranslatable(), 'Article comment body is translatable.');
$definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['subject'];
$definition = $entity_field_manager->getFieldDefinitions('comment', 'comment_article')['subject'];
$this->assertFalse($definition->isTranslatable(), 'Article comment subject is not translatable.');
$definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['comment_body'];
$definition = $entity_field_manager->getFieldDefinitions('comment', 'comment')['comment_body'];
$this->assertFalse($definition->isTranslatable(), 'Page comment body is not translatable.');
$definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['subject'];
$definition = $entity_field_manager->getFieldDefinitions('comment', 'comment')['subject'];
$this->assertFalse($definition->isTranslatable(), 'Page comment subject is not translatable.');
// Test that translation can be enabled for base fields.
@ -123,7 +124,7 @@ class ContentTranslationSettingsTest extends BrowserTestBase {
$this->assertSettings('entity_test_mul', 'entity_test_mul', TRUE, $edit);
$field_override = BaseFieldOverride::loadByName('entity_test_mul', 'entity_test_mul', 'name');
$this->assertTrue($field_override->isTranslatable(), 'Base fields can be overridden with a base field bundle override entity.');
$definitions = $this->entityManager()->getFieldDefinitions('entity_test_mul', 'entity_test_mul');
$definitions = $entity_field_manager->getFieldDefinitions('entity_test_mul', 'entity_test_mul');
$this->assertTrue($definitions['name']->isTranslatable() && !$definitions['user_id']->isTranslatable(), 'Base field bundle overrides were correctly altered.');
// Test that language settings are correctly stored.
@ -163,7 +164,7 @@ class ContentTranslationSettingsTest extends BrowserTestBase {
$edit = ['settings[node][article][fields][body]' => $translatable];
$this->assertSettings('node', 'article', TRUE, $edit);
$field = FieldConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$definitions = $entity_field_manager->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
$this->assertEqual($field->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
@ -171,9 +172,9 @@ class ContentTranslationSettingsTest extends BrowserTestBase {
$translatable = !$translatable;
$edit = ['translatable' => $translatable];
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body', $edit, t('Save settings'));
\Drupal::entityManager()->clearCachedFieldDefinitions();
$entity_field_manager->clearCachedFieldDefinitions();
$field = FieldConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$definitions = $entity_field_manager->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
$this->assertEqual($field->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
}

View File

@ -404,7 +404,7 @@ class DateTimeFieldTest extends DateTestBase {
],
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Display creation form.
$this->drupalGet('entity_test/add');
@ -440,7 +440,7 @@ class DateTimeFieldTest extends DateTestBase {
],
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Go to the form display page to assert that increment option does appear on Date Time
$fieldEditUrl = 'entity_test/structure/entity_test/form-display';
@ -506,7 +506,7 @@ class DateTimeFieldTest extends DateTestBase {
],
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Display creation form.
$this->drupalGet('entity_test/add');
@ -546,7 +546,7 @@ class DateTimeFieldTest extends DateTestBase {
],
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Test the widget for validation notifications.
foreach ($this->datelistDataProvider($field_label) as $data) {
@ -704,7 +704,7 @@ class DateTimeFieldTest extends DateTestBase {
], 'Default value has been stored successfully');
// Clear field cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is today.
$new_node = Node::create(['type' => 'date_content']);
@ -742,7 +742,7 @@ class DateTimeFieldTest extends DateTestBase {
], 'Default value has been stored successfully');
// Clear field cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is +90
// days.
@ -768,7 +768,7 @@ class DateTimeFieldTest extends DateTestBase {
$this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully');
// Clear field cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Create a new node to check that datetime field default value is not
// set.

View File

@ -232,7 +232,7 @@ function field_entity_bundle_delete($entity_type_id, $bundle) {
// config entity type so they are not part of the config dependencies.
// Gather a list of all entity reference fields.
$map = \Drupal::entityManager()->getFieldMapByFieldType('entity_reference');
$map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('entity_reference');
$ids = [];
foreach ($map as $type => $info) {
foreach ($info as $name => $data) {

View File

@ -310,7 +310,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* If the field definition is invalid.
*/
protected function preSaveNew(EntityStorageInterface $storage) {
$entity_manager = \Drupal::entityManager();
$entity_field_manager = \Drupal::service('entity_field.manager');
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
// Assign the ID.
@ -324,7 +324,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
}
// Disallow reserved field names.
$disallowed_field_names = array_keys($entity_manager->getBaseFieldDefinitions($this->getTargetEntityTypeId()));
$disallowed_field_names = array_keys($entity_field_manager->getBaseFieldDefinitions($this->getTargetEntityTypeId()));
if (in_array($this->getName(), $disallowed_field_names)) {
throw new FieldException("Attempt to create field storage {$this->getName()} which is reserved by entity type {$this->getTargetEntityTypeId()}.");
}
@ -336,7 +336,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
}
$this->module = $field_type['provider'];
// Notify the entity manager.
// Notify the field storage definition listener.
\Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
}
@ -496,7 +496,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*/
public function getBundles() {
if (!$this->isDeleted()) {
$map = \Drupal::entityManager()->getFieldMap();
$map = \Drupal::service('entity_field.manager')->getFieldMap();
if (isset($map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'])) {
return $map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'];
}

View File

@ -90,7 +90,7 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase {
$this->assertEqual([$referenced_node->getConfigDependencyName()], $config_entity['dependencies']['content']);
// Clear field definitions cache in order to avoid stale cache values.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Create a new node to check that UUID has been converted to numeric ID.
$new_node = Node::create(['type' => 'reference_content']);

View File

@ -12,13 +12,6 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
*/
class ConfigFieldDefinitionTest extends FieldKernelTestBase {
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* @var string
*/
@ -40,7 +33,6 @@ class ConfigFieldDefinitionTest extends FieldKernelTestBase {
$this->entityType = 'entity_test';
$this->bundle = 'entity_test';
$this->createFieldWithStorage('', $this->entityType, $this->bundle);
$this->entityManager = $this->container->get('entity.manager');
// Create a second field on 'entity_test_rev'.
$this->installEntitySchema('entity_test_rev');
@ -51,7 +43,7 @@ class ConfigFieldDefinitionTest extends FieldKernelTestBase {
* Makes sure a field definition is exposed for a configurable field.
*/
public function testBundleFieldDefinition() {
$definitions = $this->entityManager->getFieldDefinitions($this->entityType, $this->bundle);
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityType, $this->bundle);
$this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()]));
$this->assertTrue($definitions[$this->fieldTestData->field->getName()] instanceof FieldDefinitionInterface);
// Make sure fields on other entity types are not exposed.
@ -62,7 +54,7 @@ class ConfigFieldDefinitionTest extends FieldKernelTestBase {
* Makes sure a field storage definition is exposed for a configurable field.
*/
public function testFieldStorageDefinition() {
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityType);
$field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entityType);
$this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()]));
$this->assertTrue($field_storage_definitions[$this->fieldTestData->field->getName()] instanceof FieldStorageDefinitionInterface);
// Make sure storages on other entity types are not exposed.

View File

@ -216,7 +216,7 @@ class FieldCrudTest extends FieldKernelTestBase {
]);
$field->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Check that no table has been created for the field.
$this->assertFalse(\Drupal::database()->schema()->tableExists('entity_test__' . $field_storage->getName()));

View File

@ -80,7 +80,7 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
public function save(array $form, FormStateInterface $form_state) {
$this->messenger()->addStatus($this->t('Saved the %label @entity-type.', ['%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()]));
$this->entity->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$form_state->setRedirectUrl($this->entity->toUrl('collection'));
}

View File

@ -64,7 +64,7 @@ class ManageDisplayTest extends BrowserTestBase {
public function testViewModeCustom() {
// Create a field, and a node with some data for the field.
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, 'test', 'Test field');
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// For this test, use a formatter setting value that is an integer unlikely
// to appear in a rendered node other than as part of the field being tested
// (for example, unlikely to be part of the "Submitted by ... on ..." line).
@ -239,7 +239,7 @@ class ManageDisplayTest extends BrowserTestBase {
public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $message, $not_exists) {
// Make sure caches on the tester side are refreshed after changes
// submitted on the tested side.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Render a cloned node, so that we do not alter the original.
$clone = clone $node;

View File

@ -167,7 +167,7 @@ class ManageDisplayTest extends WebDriverTestBase {
$button_save->click();
// Assert the third party settings.
$this->entity_manager->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$this->drupalGet($manage_display);
$id = 'node.' . $this->type . '.default';
@ -316,7 +316,7 @@ class ManageDisplayTest extends WebDriverTestBase {
$this->drupalGet($manage_display);
// Assert the third party settings.
$this->entity_manager->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */
$display = $form_storage->loadUnchanged('node.' . $this->type . '.default');

View File

@ -1734,10 +1734,11 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
$return = $references[$file->id()][$age];
// Filter the static cache down to the requested entries. The usual static
// cache is very small so this will be very fast.
$entity_field_manager = \Drupal::service('entity_field.manager');
if ($field || $field_type) {
foreach ($return as $field_name => $data) {
foreach (array_keys($data) as $entity_type_id) {
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type_id);
$field_storage_definitions = $entity_field_manager->getFieldStorageDefinitions($entity_type_id);
$current_field = $field_storage_definitions[$field_name];
if (($field_type && $current_field->getType() != $field_type) || ($field && $field->uuid() != $current_field->uuid())) {
unset($return[$field_name][$entity_type_id]);

View File

@ -346,7 +346,7 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
array_pop($array_parents);
$previously_uploaded_count = count(Element::children(NestedArray::getValue($form, $array_parents))) - 1;
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($element['#entity_type']);
$field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($element['#entity_type']);
$field_storage = $field_storage_definitions[$element['#field_name']];
$newly_uploaded_count = count($values['fids']);
$total_uploaded_count = $newly_uploaded_count + $previously_uploaded_count;

View File

@ -45,7 +45,7 @@ class EntityFile extends EntityContentBase {
protected function processStubRow(Row $row) {
// We stub the uri value ourselves so we can create a real stub file for it.
if (!$row->getDestinationProperty('uri')) {
$field_definitions = $this->entityManager
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($this->storage->getEntityTypeId(),
$this->getKey('bundle'));
$value = UriItem::generateSampleValue($field_definitions['uri']);

View File

@ -298,7 +298,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$this->fieldUIAddNewField('admin/structure/comment/manage/comment', $name, $label, 'file', $storage_edit);
// Manually clear cache on the tester side.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Create node.
$edit = [

View File

@ -81,7 +81,7 @@ class FileOnTranslatedEntityTest extends FileFieldTestBase {
*/
public function testSyncedFiles() {
// Verify that the file field on the "Basic page" node type is translatable.
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'page');
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
$this->assertTrue($definitions[$this->fieldName]->isTranslatable(), 'Node file field is translatable.');
// Create a default language node.

View File

@ -70,7 +70,7 @@ class PrivateFileOnTranslatedEntityTest extends FileFieldTestBase {
*/
public function testPrivateLanguageFile() {
// Verify that the file field on the "Basic page" node type is translatable.
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'page');
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
$this->assertTrue($definitions[$this->fieldName]->isTranslatable(), 'Node file field is translatable.');
// Create a default language node.

View File

@ -125,20 +125,20 @@ class ForumController extends ControllerBase {
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
$entity_manager = $container->get('entity.manager');
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $container->get('entity_type.manager');
return new static(
$container->get('forum_manager'),
$entity_manager->getStorage('taxonomy_vocabulary'),
$entity_manager->getStorage('taxonomy_term'),
$entity_type_manager->getStorage('taxonomy_vocabulary'),
$entity_type_manager->getStorage('taxonomy_term'),
$container->get('current_user'),
$entity_manager->getAccessControlHandler('node'),
$entity_manager->getFieldMap(),
$entity_manager->getStorage('node_type'),
$entity_type_manager->getAccessControlHandler('node'),
$container->get('entity_field.manager')->getFieldMap(),
$entity_type_manager->getStorage('node_type'),
$container->get('renderer'),
$entity_manager->getDefinition('node'),
$entity_manager->getDefinition('comment')
$entity_type_manager->getDefinition('node'),
$entity_type_manager->getDefinition('comment')
);
}

View File

@ -376,7 +376,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
];
$this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.$field_name/storage", $edit, t('Save field settings'));
// Clear field definition cache so the new default image is detected.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$default_image = $field_storage->getSetting('default_image');
$file = \Drupal::service('entity.repository')->loadEntityByUuid('file', $default_image['uuid']);
@ -429,7 +429,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
$this->getSession()->getPage()->pressButton(t('Save field settings'));
// Clear field definition cache so the new default image is detected.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$default_image = $field_storage->getSetting('default_image');
$this->assertFalse($default_image['uuid'], 'Default image removed from field.');
@ -446,7 +446,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
];
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $private_field_name . '/storage', $edit, t('Save field settings'));
// Clear field definition cache so the new default image is detected.
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$private_field_storage = FieldStorageConfig::loadByName('node', $private_field_name);
$default_image = $private_field_storage->getSetting('default_image');

View File

@ -92,7 +92,7 @@ class ImageOnTranslatedEntityTest extends ImageFieldTestBase {
// Verify that the image field on the "Basic basic" node type is
// translatable.
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'basicpage');
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'basicpage');
$this->assertTrue($definitions[$this->fieldName]->isTranslatable(), 'Node image field is translatable.');
// Create a default language node.

View File

@ -53,7 +53,7 @@ class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase {
])->save();
// Ensure that the field is translated when access through the API.
$this->assertEqual('Translated Revision ID', \Drupal::entityManager()->getBaseFieldDefinitions('node')['vid']->getLabel());
$this->assertEqual('Translated Revision ID', \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('node')['vid']->getLabel());
// Assert there are no updates.
$this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates());

View File

@ -189,7 +189,7 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
if (!$defaults) {
// Get the default max_length of a menu link title from the base field
// definition.
$field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content');
$field_definitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content');
$max_length = $field_definitions['title']->getSetting('max_length');
$description_max_length = $field_definitions['description']->getSetting('max_length');
$defaults = [

View File

@ -63,12 +63,12 @@ class MenuUiNodeTest extends BrowserTestBase {
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.roles:authenticated');
// Verify that the menu link title has the correct maxlength.
$title_max_length = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content')['title']->getSetting('max_length');
$title_max_length = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content')['title']->getSetting('max_length');
$this->drupalGet('node/add/page');
$this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node add form.');
// Verify that the menu link description has the correct maxlength.
$description_max_length = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content')['description']->getSetting('max_length');
$description_max_length = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content')['description']->getSetting('max_length');
$this->drupalGet('node/add/page');
$this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/', 'Menu link description field has correct maxlength in node add form.');

View File

@ -2,9 +2,10 @@
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\TypedData\TranslatableInterface;
@ -79,13 +80,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @see \Drupal\migrate\Plugin\migrate\destination\EntityRevision
*/
class EntityContentBase extends Entity implements HighestIdInterface {
use DeprecatedServicePropertyTrait;
/**
* Entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Field type plugin manager.
@ -109,14 +116,14 @@ class EntityContentBase extends Entity implements HighestIdInterface {
* The storage for this entity type.
* @param array $bundles
* The list of bundles this entity type has.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles);
$this->entityManager = $entity_manager;
$this->entityFieldManager = $entity_field_manager;
$this->fieldTypeManager = $field_type_manager;
}
@ -130,9 +137,9 @@ class EntityContentBase extends Entity implements HighestIdInterface {
$plugin_id,
$plugin_definition,
$migration,
$container->get('entity.manager')->getStorage($entity_type),
$container->get('entity_type.manager')->getStorage($entity_type),
array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
$container->get('entity.manager'),
$container->get('entity_field.manager'),
$container->get('plugin.manager.field.field_type')
);
}
@ -272,7 +279,7 @@ class EntityContentBase extends Entity implements HighestIdInterface {
}
// Populate any required fields not already populated.
$fields = $this->entityManager
$fields = $this->entityFieldManager
->getFieldDefinitions($this->storage->getEntityTypeId(), $bundle_key);
foreach ($fields as $field_name => $field_definition) {
if ($field_definition->isRequired() && is_null($row->getDestinationProperty($field_name))) {
@ -346,7 +353,7 @@ class EntityContentBase extends Entity implements HighestIdInterface {
protected function getDefinitionFromEntity($key) {
$entity_type_id = static::getEntityTypeId($this->getPluginId());
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $definitions */
$definitions = $this->entityManager->getBaseFieldDefinitions($entity_type_id);
$definitions = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id);
$field_definition = $definitions[$key];
return [

View File

@ -3,7 +3,7 @@
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
@ -114,11 +114,11 @@ class EntityRevision extends EntityContentBase {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager) {
$plugin_definition += [
'label' => new TranslatableMarkup('@entity_type revisions', ['@entity_type' => $storage->getEntityType()->getSingularLabel()]),
];
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_field_manager, $field_type_manager);
}
/**

View File

@ -92,7 +92,7 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
$this->getMock(MigrationInterface::class),
$this->storage,
[],
$this->container->get('entity.manager'),
$this->container->get('entity_field.manager'),
$this->container->get('plugin.manager.field.field_type')
);
}

View File

@ -33,7 +33,7 @@ class EntityContentBaseTest extends EntityTestBase {
$this->migration->reveal(),
$this->storage->reveal(),
$bundles,
$this->entityManager->reveal(),
$this->entityFieldManager->reveal(),
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
$entity = $this->prophesize(ContentEntityInterface::class);
// Assert that save is called.
@ -60,7 +60,7 @@ class EntityContentBaseTest extends EntityTestBase {
$this->migration->reveal(),
$this->storage->reveal(),
$bundles,
$this->entityManager->reveal(),
$this->entityFieldManager->reveal(),
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
$destination->setEntity(FALSE);
$this->setExpectedException(MigrateException::class, 'Unable to get entity');
@ -74,7 +74,7 @@ class EntityContentBaseTest extends EntityTestBase {
// An entity type without a language.
$this->entityType->getKey('langcode')->willReturn('');
$this->entityType->getKey('id')->willReturn('id');
$this->entityManager->getBaseFieldDefinitions('foo')
$this->entityFieldManager->getBaseFieldDefinitions('foo')
->willReturn(['id' => BaseFieldDefinitionTest::create('integer')]);
$destination = new EntityTestDestination(
@ -84,7 +84,7 @@ class EntityContentBaseTest extends EntityTestBase {
$this->migration->reveal(),
$this->storage->reveal(),
[],
$this->entityManager->reveal(),
$this->entityFieldManager->reveal(),
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
);
$this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.');

View File

@ -2,7 +2,6 @@
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
@ -33,8 +32,6 @@ class EntityRevisionTest extends EntityTestBase {
$this->entityType->getPluralLabel()->willReturn('bar');
$this->storage->getEntityType()->willReturn($this->entityType->reveal());
$this->storage->getEntityTypeId()->willReturn('foo');
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
}
/**
@ -43,7 +40,7 @@ class EntityRevisionTest extends EntityTestBase {
public function testUnrevisionable() {
$this->entityType->getKey('id')->willReturn('id');
$this->entityType->getKey('revision')->willReturn('');
$this->entityManager->getBaseFieldDefinitions('foo')
$this->entityFieldManager->getBaseFieldDefinitions('foo')
->willReturn([
'id' => BaseFieldDefinitionTest::create('integer'),
]);
@ -55,7 +52,7 @@ class EntityRevisionTest extends EntityTestBase {
$this->migration->reveal(),
$this->storage->reveal(),
[],
$this->entityManager->reveal(),
$this->entityFieldManager->reveal(),
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
);
$this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support revisions.');
@ -69,7 +66,7 @@ class EntityRevisionTest extends EntityTestBase {
$this->entityType->getKey('id')->willReturn('id');
$this->entityType->getKey('revision')->willReturn('vid');
$this->entityType->getKey('langcode')->willReturn('');
$this->entityManager->getBaseFieldDefinitions('foo')
$this->entityFieldManager->getBaseFieldDefinitions('foo')
->willReturn([
'id' => BaseFieldDefinitionTest::create('integer'),
'vid' => BaseFieldDefinitionTest::create('integer'),
@ -82,7 +79,7 @@ class EntityRevisionTest extends EntityTestBase {
$this->migration->reveal(),
$this->storage->reveal(),
[],
$this->entityManager->reveal(),
$this->entityFieldManager->reveal(),
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
);
$this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.');

View File

@ -7,7 +7,7 @@
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
@ -33,11 +33,10 @@ class EntityTestBase extends UnitTestCase {
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
/**
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityManager;
protected $entityFieldManager;
/**
* {@inheritdoc}
@ -53,7 +52,7 @@ class EntityTestBase extends UnitTestCase {
$this->storage->getEntityType()->willReturn($this->entityType->reveal());
$this->storage->getEntityTypeId()->willReturn('foo');
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
$this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
}
}

View File

@ -3,7 +3,9 @@
namespace Drupal\node\Plugin\views\wizard;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\wizard\WizardPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -37,6 +39,13 @@ class Node extends WizardPluginBase {
*/
protected $entityDisplayRepository;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Node constructor.
*
@ -50,8 +59,10 @@ class Node extends WizardPluginBase {
* The entity bundle info service.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $bundle_info_service);
if (!$entity_display_repository) {
@ -59,6 +70,11 @@ class Node extends WizardPluginBase {
$entity_display_repository = \Drupal::service('entity_display.repository');
}
$this->entityDisplayRepository = $entity_display_repository;
if (!$entity_field_manager) {
@trigger_error('The entity_field.manager service must be passed to ' . __METHOD__ . ', it is required before Drupal 9.0.0. See https://www.drupal.org/node/2835616.', E_USER_DEPRECATED);
$entity_field_manager = \Drupal::service('entity_field.manager');
}
$this->entityFieldManager = $entity_field_manager;
}
/**
@ -70,7 +86,8 @@ class Node extends WizardPluginBase {
$plugin_id,
$plugin_definition,
$container->get('entity_type.bundle.info'),
$container->get('entity_display.repository')
$container->get('entity_display.repository'),
$container->get('entity_field.manager')
);
}
@ -261,7 +278,7 @@ class Node extends WizardPluginBase {
$tag_fields = [];
foreach ($bundles as $bundle) {
$display = $this->entityDisplayRepository->getFormDisplay($this->entityTypeId, $bundle);
$taxonomy_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($this->entityTypeId, $bundle), function ($field_definition) {
$taxonomy_fields = array_filter($this->entityFieldManager->getFieldDefinitions($this->entityTypeId, $bundle), function (FieldDefinitionInterface $field_definition) {
return $field_definition->getType() == 'entity_reference' && $field_definition->getSetting('target_type') == 'taxonomy_term';
});
foreach ($taxonomy_fields as $field_name => $field) {

View File

@ -131,7 +131,7 @@ class NodeCreationTest extends NodeTestBase {
$this->config('system.site')->set('page.front', '/test-page')->save();
// Set "Basic page" content type to be unpublished by default.
$fields = \Drupal::entityManager()->getFieldDefinitions('node', 'page');
$fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
$fields['status']->getConfig('page')
->setDefaultValue(FALSE)
->save();

View File

@ -50,7 +50,7 @@ class NodeFieldOverridesTest extends EntityKernelTestBase {
if ($override) {
$override->delete();
}
$uid_field = \Drupal::entityManager()->getBaseFieldDefinitions('node')['uid'];
$uid_field = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('node')['uid'];
$config = $uid_field->getConfig('ponies');
$config->save();
$this->assertEquals($config->get('default_value_callback'), 'Drupal\node\Entity\Node::getDefaultEntityOwner');

View File

@ -62,7 +62,7 @@ class PathLanguageTest extends PathTestBase {
];
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'page');
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
$this->assertTrue($definitions['path']->isTranslatable(), 'Node path is translatable.');
$this->assertTrue($definitions['body']->isTranslatable(), 'Node body is translatable.');
}

View File

@ -117,7 +117,7 @@ class ResponsiveImageFieldUiTest extends WebDriverTestBase {
'image_mapping' => 'large',
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Refresh the page.
$this->drupalGet($manage_display);
$assert_session->responseContains("Select a responsive image style.");

View File

@ -3,7 +3,7 @@
namespace Drupal\user\Plugin\migrate\destination;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EmailItem;
@ -89,15 +89,15 @@ class EntityUser extends EntityContentBase {
* The storage for this entity type.
* @param array $bundles
* The list of bundles this entity type has.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager service.
* @param \Drupal\Core\Password\PasswordInterface $password
* The password service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PasswordInterface $password) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager, PasswordInterface $password) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_field_manager, $field_type_manager);
$this->password = $password;
}
@ -111,9 +111,9 @@ class EntityUser extends EntityContentBase {
$plugin_id,
$plugin_definition,
$migration,
$container->get('entity.manager')->getStorage($entity_type),
$container->get('entity_type.manager')->getStorage($entity_type),
array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
$container->get('entity.manager'),
$container->get('entity_field.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('password')
);
@ -157,7 +157,7 @@ class EntityUser extends EntityContentBase {
// Email address is not defined as required in the base field definition but
// is effectively required by the UserMailRequired constraint. This means
// that Entity::processStubRow() did not populate it - we do it here.
$field_definitions = $this->entityManager
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($this->storage->getEntityTypeId(),
$this->getKey('bundle'));
$mail = EmailItem::generateSampleValue($field_definitions['mail']);

View File

@ -149,7 +149,7 @@ function user_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
* preprocess stage.
*/
function user_picture_enabled() {
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('user', 'user');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', 'user');
return isset($field_definitions['user_picture']);
}

View File

@ -2,9 +2,11 @@
namespace Drupal\views;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\Entity\Sql\TableMappingInterface;
@ -21,6 +23,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterface {
use StringTranslationTrait;
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* Entity type for this views data handler instance.
@ -58,11 +66,18 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
protected $fieldStorageDefinitions;
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Constructs an EntityViewsData object.
@ -71,19 +86,22 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
* The entity type to provide views integration for.
* @param \Drupal\Core\Entity\Sql\SqlEntityStorageInterface $storage_controller
* The storage handler used for this entity type.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
* The translation manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) {
public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager, EntityFieldManagerInterface $entity_field_manager = NULL) {
$this->entityType = $entity_type;
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entity_type_manager;
$this->storage = $storage_controller;
$this->moduleHandler = $module_handler;
$this->setStringTranslation($translation_manager);
$this->entityFieldManager = $entity_field_manager;
}
/**
@ -92,11 +110,11 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('entity.manager'),
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('entity_type.manager'),
$container->get('module_handler'),
$container->get('string_translation'),
$container->get('typed_data_manager')
$container->get('entity_field.manager')
);
}
@ -107,7 +125,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
*/
protected function getFieldStorageDefinitions() {
if (!isset($this->fieldStorageDefinitions)) {
$this->fieldStorageDefinitions = $this->entityManager->getFieldStorageDefinitions($this->entityType->id());
$this->fieldStorageDefinitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityType->id());
}
return $this->fieldStorageDefinitions;
}
@ -266,7 +284,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
// Load all typed data definitions of all fields. This should cover each of
// the entity base, revision, data tables.
$field_definitions = $this->entityManager->getBaseFieldDefinitions($this->entityType->id());
$field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id());
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
if ($table_mapping = $this->storage->getTableMapping($field_definitions)) {
// Fetch all fields that can appear in both the base table and the data
@ -582,7 +600,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
// @see https://www.drupal.org/node/2322949
if ($entity_type_id = $field_definition->getItemDefinition()->getSetting('target_type')) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
if ($entity_type instanceof ContentEntityType) {
$views_field['relationship'] = [
'base' => $this->getViewsTableForEntityType($entity_type),

View File

@ -23,6 +23,13 @@ trait FieldAPIHandlerTrait {
*/
protected $fieldStorageDefinition;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Gets the field definition.
*
@ -52,7 +59,7 @@ trait FieldAPIHandlerTrait {
*/
protected function getFieldStorageDefinition() {
if (!$this->fieldStorageDefinition) {
$field_storage_definitions = $this->getEntityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
$field_storage_definitions = $this->getEntityFieldManager()->getFieldStorageDefinitions($this->definition['entity_type']);
$this->fieldStorageDefinition = $field_storage_definitions[$this->definition['field_name']];
}
return $this->fieldStorageDefinition;
@ -71,4 +78,17 @@ trait FieldAPIHandlerTrait {
return $this->entityManager;
}
/**
* Returns the entity field manager.
*
* @return \Drupal\Core\Entity\EntityManagerInterface
* The entity field manager.
*/
protected function getEntityFieldManager() {
if (!isset($this->entityFieldManager)) {
$this->entityFieldManager = \Drupal::service('entity_field.manager');
}
return $this->entityFieldManager;
}
}

View File

@ -9,7 +9,9 @@ namespace Drupal\Tests\views\Unit;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Sql\DefaultTableMapping;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
@ -49,13 +51,6 @@ class EntityViewsDataTest extends UnitTestCase {
*/
protected $entityStorage;
/**
* The mocked entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The mocked entity field manager.
*
@ -99,9 +94,8 @@ class EntityViewsDataTest extends UnitTestCase {
$this->entityStorage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
->disableOriginalConstructor()
->getMock();
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$this->entityFieldManager = $this->getMock('Drupal\Core\Entity\EntityFieldManagerInterface');
$this->entityTypeManager = $this->getMock('Drupal\Core\Entity\EntityTypeManagerInterface');
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$this->entityFieldManager = $this->createMock(EntityFieldManagerInterface::class);
$typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
$typed_data_manager->expects($this->any())
@ -134,7 +128,7 @@ class EntityViewsDataTest extends UnitTestCase {
$this->baseEntityType->setStringTranslation($this->translationManager);
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->viewsData = new TestEntityViewsData($this->baseEntityType, $this->entityStorage, $this->entityManager, $this->moduleHandler, $this->translationManager);
$this->viewsData = new TestEntityViewsData($this->baseEntityType, $this->entityStorage, $this->entityTypeManager, $this->moduleHandler, $this->translationManager, $this->entityFieldManager);
$field_type_manager = $this->getMockBuilder('Drupal\Core\Field\FieldTypePluginManager')
->disableOriginalConstructor()
@ -151,9 +145,8 @@ class EntityViewsDataTest extends UnitTestCase {
$container = new ContainerBuilder();
$container->set('plugin.manager.field.field_type', $field_type_manager);
$container->set('entity.manager', $this->entityManager);
$container->set('entity_field.manager', $this->entityFieldManager);
$container->set('entity_type.manager', $this->entityTypeManager);
$container->set('entity_field.manager', $this->entityFieldManager);
$container->set('typed_data_manager', $typed_data_manager);
$container->set('state', $state->reveal());
\Drupal::setContainer($container);
@ -427,7 +420,7 @@ class EntityViewsDataTest extends UnitTestCase {
->willReturn(StringItem::schema($string_field_storage_definition));
// Setup the user_id entity reference field.
$this->entityManager->expects($this->any())
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->willReturnMap([
['user', TRUE, static::userEntityInfo()],
@ -456,7 +449,7 @@ class EntityViewsDataTest extends UnitTestCase {
->method('getSchema')
->willReturn(IntegerItem::schema($revision_id_field_storage_definition));
$this->entityManager->expects($this->any())
$this->entityFieldManager->expects($this->any())
->method('getFieldStorageDefinitions')
->willReturn([
'id' => $id_field_storage_definition,
@ -484,7 +477,7 @@ class EntityViewsDataTest extends UnitTestCase {
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE),
];
$this->entityManager->expects($this->any())
$this->entityFieldManager->expects($this->any())
->method('getBaseFieldDefinitions')
->will($this->returnValueMap([
['user', $user_base_field_definitions],
@ -613,7 +606,7 @@ class EntityViewsDataTest extends UnitTestCase {
];
$entity_test_type = new ConfigEntityType(['id' => 'entity_test_bundle']);
$this->entityManager->expects($this->any())
$this->entityFieldManager->expects($this->any())
->method('getBaseFieldDefinitions')
->will($this->returnValueMap([
['user', $user_base_field_definitions],
@ -684,7 +677,7 @@ class EntityViewsDataTest extends UnitTestCase {
$this->setupFieldStorageDefinition();
$user_entity_type = static::userEntityInfo();
$this->entityManager->expects($this->any())
$this->entityTypeManager->expects($this->any())
->method('getDefinition')
->will($this->returnValueMap([
['user', TRUE, $user_entity_type],
@ -769,7 +762,7 @@ class EntityViewsDataTest extends UnitTestCase {
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE),
];
$this->entityManager->expects($this->any())
$this->entityFieldManager->expects($this->any())
->method('getBaseFieldDefinitions')
->will($this->returnValueMap([
['user', $user_base_field_definitions],

View File

@ -256,8 +256,9 @@ function views_entity_field_label($entity_type, $field_name) {
$label_counter = [];
$all_labels = [];
// Count the amount of fields per label per field storage.
$entity_field_manager = \Drupal::service('entity_field.manager');
foreach (array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type)) as $bundle) {
$bundle_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
$bundle_fields = array_filter($entity_field_manager->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
return $field_definition instanceof FieldConfigInterface;
});
if (isset($bundle_fields[$field_name])) {

View File

@ -83,7 +83,7 @@ class DefaultTableMappingIntegrationTest extends EntityKernelTestBase {
* @covers ::getTableNames
*/
public function testGetTableNames() {
$storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test_mulrev');
$storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_mulrev');
$dedicated_data_table = $this->tableMapping->getDedicatedDataTableName($storage_definitions['multivalued_base_field']);
$dedicated_revision_table = $this->tableMapping->getDedicatedRevisionTableName($storage_definitions['multivalued_base_field']);

View File

@ -63,7 +63,7 @@ class EntityBundleFieldTest extends EntityKernelTestBase {
$this->assertTrue($entity->hasField('custom_bundle_field'));
// Ensure that the field exists in the field map.
$field_map = \Drupal::entityManager()->getFieldMap();
$field_map = \Drupal::service('entity_field.manager')->getFieldMap();
$this->assertEqual($field_map['entity_test_update']['custom_bundle_field'], ['type' => 'string', 'bundles' => ['custom' => 'custom']]);
$entity->custom_bundle_field->value = 'swanky';
@ -103,7 +103,7 @@ class EntityBundleFieldTest extends EntityKernelTestBase {
$this->assertEqual(1, $result->fetchField(), 'Field data has been deleted');
// Ensure that the field no longer exists in the field map.
$field_map = \Drupal::entityManager()->getFieldMap();
$field_map = \Drupal::service('entity_field.manager')->getFieldMap();
$this->assertFalse(isset($field_map['entity_test_update']['custom_bundle_field']));
// Purge field data, and check that the storage definition has been

View File

@ -415,7 +415,7 @@ class EntityFieldTest extends EntityKernelTestBase {
protected function doTestIntrospection($entity_type) {
// Test getting metadata upfront. The entity types used for this test have
// a default bundle that is the same as the entity type.
$definitions = \Drupal::entityManager()->getFieldDefinitions($entity_type, $entity_type);
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_type, $entity_type);
$this->assertEqual($definitions['name']->getType(), 'string', $entity_type . ': Name field found.');
$this->assertEqual($definitions['user_id']->getType(), 'entity_reference', $entity_type . ': User field found.');
$this->assertEqual($definitions['field_test_text']->getType(), 'text', $entity_type . ': Test-text-field field found.');
@ -636,13 +636,13 @@ class EntityFieldTest extends EntityKernelTestBase {
'type' => 'page',
'name' => 'page',
])->save();
$this->entityManager->clearCachedFieldDefinitions();
$fields = $this->entityManager->getFieldDefinitions('node', 'page');
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
$override = $fields['status']->getConfig('page');
$override->setLabel($this->randomString())->save();
\Drupal::state()->set('entity_test.node_remove_status_field', TRUE);
$this->entityManager->clearCachedFieldDefinitions();
$fields = $this->entityManager->getFieldDefinitions('node', 'page');
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'page');
// A base field override on a non-existing base field should not cause a
// field definition to come into existence.
$this->assertFalse(isset($fields['status']), 'Node\'s status base field does not exist.');
@ -657,11 +657,11 @@ class EntityFieldTest extends EntityKernelTestBase {
// First make sure the bundle field override in code, which is provided by
// the test entity works.
entity_test_create_bundle('some_test_bundle', 'Some test bundle', 'entity_test_field_override');
$field_definitions = $this->entityManager->getFieldDefinitions('entity_test_field_override', 'entity_test_field_override');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_test_field_override', 'entity_test_field_override');
$this->assertEqual($field_definitions['name']->getDescription(), 'The default description.');
$this->assertNull($field_definitions['name']->getTargetBundle());
$field_definitions = $this->entityManager->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getDescription(), 'Custom description.');
$this->assertEqual($field_definitions['name']->getTargetBundle(), 'some_test_bundle');
@ -671,8 +671,8 @@ class EntityFieldTest extends EntityKernelTestBase {
$field_config->save();
// Make sure both overrides are present.
$this->entityManager->clearCachedFieldDefinitions();
$field_definitions = $this->entityManager->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getDescription(), 'Custom description.');
$this->assertEqual($field_definitions['name']->getTargetBundle(), 'some_test_bundle');
$this->assertFalse($field_definitions['name']->isTranslatable());

View File

@ -46,7 +46,7 @@ class EntitySchemaTest extends EntityKernelTestBase {
public function testCustomFieldCreateDelete() {
// Install the module which adds the field.
$this->installModule('entity_schema_test');
$storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test_update');
$storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');
$this->assertNotNull($storage_definitions['custom_base_field'], 'Base field definition found.');
$this->assertNotNull($storage_definitions['custom_bundle_field'], 'Bundle field definition found.');
@ -306,8 +306,9 @@ class EntitySchemaTest extends EntityKernelTestBase {
$this->installModule('entity_schema_test');
$this->updateEntityType(TRUE);
$fields = ['revision_log', 'uuid'];
$entity_field_manager = \Drupal::service('entity_field.manager');
foreach ($fields as $field_name) {
$original_definition = $this->entityManager->getBaseFieldDefinitions('entity_test_update')[$field_name];
$original_definition = $entity_field_manager->getBaseFieldDefinitions('entity_test_update')[$field_name];
$new_definition = clone $original_definition;
$new_definition->setLabel($original_definition->getLabel() . ', the other one');
$this->assertTrue($this->entityManager->getStorage('entity_test_update')

View File

@ -688,13 +688,14 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// in field definitions.
$entity_type = 'entity_test_mulrev';
$this->state->set('entity_test.field_definitions.translatable', ['name' => FALSE]);
$this->entityManager->clearCachedFieldDefinitions();
$definitions = $this->entityManager->getBaseFieldDefinitions($entity_type);
$entity_field_manager = \Drupal::service('entity_field.manager');
$entity_field_manager->clearCachedFieldDefinitions();
$definitions = $entity_field_manager->getBaseFieldDefinitions($entity_type);
$this->assertFalse($definitions['name']->isTranslatable(), 'Field translatability can be disabled programmatically.');
$this->state->set('entity_test.field_definitions.translatable', ['name' => TRUE]);
$this->entityManager->clearCachedFieldDefinitions();
$definitions = $this->entityManager->getBaseFieldDefinitions($entity_type);
$entity_field_manager->clearCachedFieldDefinitions();
$definitions = $entity_field_manager->getBaseFieldDefinitions($entity_type);
$this->assertTrue($definitions['name']->isTranslatable(), 'Field translatability can be enabled programmatically.');
// Check that field translatability is disabled by default.
@ -712,11 +713,11 @@ class EntityTranslationTest extends EntityLanguageTestBase {
];
foreach ($translatable_fields as $name => $translatable) {
$this->state->set('entity_test.field_definitions.translatable', [$name => $translatable]);
$this->entityManager->clearCachedFieldDefinitions();
$entity_field_manager->clearCachedFieldDefinitions();
$message = format_string('Field %field cannot be translatable.', ['%field' => $name]);
try {
$this->entityManager->getBaseFieldDefinitions($entity_type);
$entity_field_manager->getBaseFieldDefinitions($entity_type);
$this->fail($message);
}
catch (\LogicException $e) {

View File

@ -104,7 +104,7 @@ class EntityTypedDataDefinitionTest extends KernelTestBase {
$field_definitions = $entity_definition->getPropertyDefinitions();
// Comparison should ignore the internal static cache, so compare the
// serialized objects instead.
$this->assertEqual(serialize($field_definitions), serialize(\Drupal::entityManager()->getBaseFieldDefinitions('node')));
$this->assertEqual(serialize($field_definitions), serialize(\Drupal::service('entity_field.manager')->getBaseFieldDefinitions('node')));
$this->assertEqual($entity_definition->getPropertyDefinition('title')->getItemDefinition()->getDataType(), 'field_item:string');
$this->assertNull($entity_definition->getMainPropertyName());
$this->assertNull($entity_definition->getPropertyDefinition('invalid'));

View File

@ -50,7 +50,7 @@ class FieldItemTest extends EntityKernelTestBase {
])->save();
$this->entityTypeManager->clearCachedDefinitions();
$definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
$definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
$this->assertTrue(!empty($definitions[$this->fieldName]));
}

View File

@ -123,6 +123,102 @@ class EntityManagerTest extends UnitTestCase {
$this->entityManager->clearCachedDefinitions();
}
/**
* Tests the clearCachedFieldDefinitions() method.
*
* @covers ::clearCachedFieldDefinitions
*
* @expectedDeprecation EntityManagerInterface::clearCachedFieldDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::clearCachedFieldDefinitions() instead. See https://www.drupal.org/node/2549139.
*/
public function testClearCachedFieldDefinitions() {
$this->entityFieldManager->clearCachedFieldDefinitions()->shouldBeCalled();
$this->entityManager->clearCachedFieldDefinitions();
}
/**
* Tests the getBaseFieldDefinitions() method.
*
* @covers ::getBaseFieldDefinitions
*
* @expectedDeprecation EntityManagerInterface::getBaseFieldDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getBaseFieldDefinitions() instead. See https://www.drupal.org/node/2549139.
*/
public function testGetBaseFieldDefinitions() {
$this->entityFieldManager->getBaseFieldDefinitions('node')->shouldBeCalled()->willReturn([]);
$this->assertEquals([], $this->entityManager->getBaseFieldDefinitions('node'));
}
/**
* Tests the getFieldDefinitions() method.
*
* @covers ::getFieldDefinitions
*
* @expectedDeprecation EntityManagerInterface::getFieldDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions() instead. See https://www.drupal.org/node/2549139.
*/
public function testGetFieldDefinitions() {
$this->entityFieldManager->getFieldDefinitions('node', 'article')->shouldBeCalled()->willReturn([]);
$this->assertEquals([], $this->entityManager->getFieldDefinitions('node', 'article'));
}
/**
* Tests the getFieldStorageDefinitions() method.
*
* @covers ::getFieldStorageDefinitions
*
* @expectedDeprecation EntityManagerInterface::getFieldStorageDefinitions() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions() instead. See https://www.drupal.org/node/2549139.
*/
public function testGetFieldStorageDefinitions() {
$this->entityFieldManager->getFieldStorageDefinitions('node')->shouldBeCalled()->willReturn([]);
$this->assertEquals([], $this->entityManager->getFieldStorageDefinitions('node'));
}
/**
* Tests the getFieldMap() method.
*
* @covers ::getFieldMap
*
* @expectedDeprecation EntityManagerInterface::getFieldMap() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMap() instead. See https://www.drupal.org/node/2549139.
*/
public function testGetFieldMap() {
$this->entityFieldManager->getFieldMap()->shouldBeCalled()->willReturn([]);
$this->assertEquals([], $this->entityManager->getFieldMap());
}
/**
* Tests the setFieldMap() method.
*
* @covers ::setFieldMap
*
* @expectedDeprecation EntityManagerInterface::setFieldMap() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::setFieldMap() instead. See https://www.drupal.org/node/2549139.
*/
public function testSetFieldMap() {
$this->entityFieldManager->setFieldMap([])->shouldBeCalled();
$this->entityManager->setFieldMap([]);
}
/**
* Tests the getFieldMapByFieldType() method.
*
* @covers ::getFieldMapByFieldType
*
* @expectedDeprecation EntityManagerInterface::getFieldMapByFieldType() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMapByFieldType() instead. See https://www.drupal.org/node/2549139.
*/
public function testGetFieldMapByFieldType() {
$this->entityFieldManager->getFieldMapByFieldType('node')->shouldBeCalled()->willReturn([]);
$this->assertEquals([], $this->entityManager->getFieldMapByFieldType('node'));
}
/**
* Tests the getExtraFields() method.
*
* @covers ::getExtraFields
*
* @expectedDeprecation EntityManagerInterface::getExtraFields() is deprecated in drupal:8.0.0 and will be removed before drupal:9.0.0. Use \Drupal\Core\Entity\EntityFieldManagerInterface::getExtraFields() instead. See https://www.drupal.org/node/2549139.
*/
public function testGetExtraFields() {
$this->entityFieldManager->getExtraFields('entity_type_id', 'bundle')->shouldBeCalled()->willReturn([]);
$this->assertEquals([], $this->entityManager->getExtraFields('entity_type_id', 'bundle'));
}
/**
* Tests the getBundleInfo() method.
*