Commit a98b5876 authored by larowlan's avatar larowlan

Issue #3035953 by Berdir, andypost, vacho: Add @trigger_error() to deprecated...

Issue #3035953 by Berdir, andypost, vacho: Add @trigger_error() to deprecated EntityManager->EntityFieldManager methods
parent da94d7fc
...@@ -212,7 +212,7 @@ public function processForm($element, FormStateInterface $form_state, $form) { ...@@ -212,7 +212,7 @@ public function processForm($element, FormStateInterface $form_state, $form) {
} }
// Hide extra fields. // 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'] : []; $extra_fields = isset($extra_fields['form']) ? $extra_fields['form'] : [];
foreach ($extra_fields as $extra_field => $info) { foreach ($extra_fields as $extra_field => $info) {
if (!$this->getComponent($extra_field)) { if (!$this->getComponent($extra_field)) {
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
* in state allows to avoid this and ensures that the various steps of the * in state allows to avoid this and ensures that the various steps of the
* update process are predictable and repeatable. * update process are predictable and repeatable.
* *
* @see \Drupal\Core\Entity\EntityManagerInterface::getDefinition() * @see \Drupal\Core\Entity\EntityTypeManagerInterface::getDefinition()
* @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledDefinition() * @see \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledDefinition()
* @see \Drupal\Core\Entity\EntityManagerInterface::getFieldStorageDefinitions() * @see \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions()
* @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledFieldStorageDefinitions() * @see \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalledFieldStorageDefinitions()
* @see hook_update_N() * @see hook_update_N()
*/ */
interface EntityDefinitionUpdateManagerInterface { interface EntityDefinitionUpdateManagerInterface {
......
...@@ -157,7 +157,7 @@ protected function init() { ...@@ -157,7 +157,7 @@ protected function init() {
$default_region = $this->getDefaultRegion(); $default_region = $this->getDefaultRegion();
// Fill in defaults for extra fields. // Fill in defaults for extra fields.
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext; $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] : []; $extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : [];
foreach ($extra_fields as $name => $definition) { foreach ($extra_fields as $name => $definition) {
if (!isset($this->content[$name]) && !isset($this->hidden[$name])) { if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
...@@ -424,7 +424,7 @@ protected function getFieldDefinition($field_name) { ...@@ -424,7 +424,7 @@ protected function getFieldDefinition($field_name) {
*/ */
protected function getFieldDefinitions() { protected function getFieldDefinitions() {
if (!isset($this->fieldDefinitions)) { 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 // For "official" view modes and form modes, ignore fields whose
// definition states they should not be displayed. // definition states they should not be displayed.
if ($this->mode !== static::CUSTOM_MODE) { if ($this->mode !== static::CUSTOM_MODE) {
......
...@@ -96,7 +96,7 @@ public function calculateDependencies() { ...@@ -96,7 +96,7 @@ public function calculateDependencies() {
*/ */
public function preSave(EntityStorageInterface $storage) { public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage); parent::preSave($storage);
\Drupal::entityManager()->clearCachedFieldDefinitions(); \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
} }
/** /**
...@@ -104,7 +104,7 @@ public function preSave(EntityStorageInterface $storage) { ...@@ -104,7 +104,7 @@ public function preSave(EntityStorageInterface $storage) {
*/ */
public static function preDelete(EntityStorageInterface $storage, array $entities) { public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities); parent::preDelete($storage, $entities);
\Drupal::entityManager()->clearCachedFieldDefinitions(); \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
} }
/** /**
......
...@@ -508,12 +508,13 @@ public function getFieldMap() { ...@@ -508,12 +508,13 @@ public function getFieldMap() {
// In the second step, the per-bundle fields are added, based on the // In the second step, the per-bundle fields are added, based on the
// persistent bundle field map stored in a key value collection. This // persistent bundle field map stored in a key value collection. This
// data is managed in the EntityManager::onFieldDefinitionCreate() // data is managed in the
// and EntityManager::onFieldDefinitionDelete() methods. Rebuilding this // FieldDefinitionListener::onFieldDefinitionCreate() and
// information in the same way as base fields would not scale, as the // FieldDefinitionListener::onFieldDefinitionDelete() methods.
// time to query would grow exponentially with more fields and bundles. // Rebuilding this information in the same way as base fields would not
// A cache would be deleted during cache clears, which is the only time // scale, as the time to query would grow exponentially with more fields
// it is needed, so a key value collection is used. // 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(); $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_maps as $entity_type_id => $bundle_field_map) {
foreach ($bundle_field_map as $field_name => $map_entry) { foreach ($bundle_field_map as $field_name => $map_entry) {
......
...@@ -180,6 +180,7 @@ public function createHandlerInstance($class, EntityTypeInterface $definition = ...@@ -180,6 +180,7 @@ public function createHandlerInstance($class, EntityTypeInterface $definition =
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function getBaseFieldDefinitions($entity_type_id) { 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); return $this->container->get('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
} }
...@@ -193,19 +194,21 @@ public function getBaseFieldDefinitions($entity_type_id) { ...@@ -193,19 +194,21 @@ public function getBaseFieldDefinitions($entity_type_id) {
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function getFieldDefinitions($entity_type_id, $bundle) { 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); return $this->container->get('entity_field.manager')->getFieldDefinitions($entity_type_id, $bundle);
} }
/** /**
* {@inheritdoc} * {@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() * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldStorageDefinitions()
* instead. * instead.
* *
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function getFieldStorageDefinitions($entity_type_id) { 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); return $this->container->get('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
} }
...@@ -226,53 +229,56 @@ public function getActiveFieldStorageDefinitions($entity_type_id) { ...@@ -226,53 +229,56 @@ public function getActiveFieldStorageDefinitions($entity_type_id) {
/** /**
* {@inheritdoc} * {@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() * Use \Drupal\Core\Entity\EntityFieldManagerInterface::setFieldMap()
* instead. * instead.
* *
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function setFieldMap(array $field_map) { 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); return $this->container->get('entity_field.manager')->setFieldMap($field_map);
} }
/** /**
* {@inheritdoc} * {@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() * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMap()
* instead. * instead.
* *
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function getFieldMap() { 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(); return $this->container->get('entity_field.manager')->getFieldMap();
} }
/** /**
* {@inheritdoc} * {@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() * Use \Drupal\Core\Entity\EntityFieldManagerInterface::getFieldMapByFieldType()
* instead. * instead.
* *
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function getFieldMapByFieldType($field_type) { 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); return $this->container->get('entity_field.manager')->getFieldMapByFieldType($field_type);
} }
/** /**
* {@inheritdoc} * {@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() * Use \Drupal\Core\Field\FieldDefinitionListenerInterface::onFieldDefinitionCreate()
* instead. * instead.
* *
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition) { 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); $this->container->get('field_definition.listener')->onFieldDefinitionCreate($field_definition);
} }
...@@ -314,6 +320,7 @@ public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definiti ...@@ -314,6 +320,7 @@ public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definiti
* @see https://www.drupal.org/node/2549139 * @see https://www.drupal.org/node/2549139
*/ */
public function clearCachedFieldDefinitions() { 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(); $this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
} }
...@@ -361,8 +368,15 @@ public function getAllBundleInfo() { ...@@ -361,8 +368,15 @@ public function getAllBundleInfo() {
/** /**
* {@inheritdoc} * {@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) { 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); return $this->container->get('entity_field.manager')->getExtraFields($entity_type_id, $bundle);
} }
......
...@@ -79,10 +79,10 @@ public function getPropertyDefinitions() { ...@@ -79,10 +79,10 @@ public function getPropertyDefinitions() {
// See https://www.drupal.org/node/2169813. // See https://www.drupal.org/node/2169813.
$bundles = $this->getBundles(); $bundles = $this->getBundles();
if (is_array($bundles) && count($bundles) == 1) { 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 { else {
$this->propertyDefinitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type_id); $this->propertyDefinitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id);
} }
} }
} }
......
...@@ -232,9 +232,11 @@ public function install(array $module_list, $enable_dependencies = TRUE) { ...@@ -232,9 +232,11 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// handler can use this as an opportunity to create the necessary // handler can use this as an opportunity to create the necessary
// database tables. // database tables.
// @todo Clean this up in https://www.drupal.org/node/2350111. // @todo Clean this up in https://www.drupal.org/node/2350111.
$entity_manager = \Drupal::entityManager(); $entity_type_manager = \Drupal::entityTypeManager();
$update_manager = \Drupal::entityDefinitionUpdateManager(); $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) { if ($entity_type->getProvider() == $module) {
$update_manager->installEntityType($entity_type); $update_manager->installEntityType($entity_type);
} }
...@@ -242,7 +244,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { ...@@ -242,7 +244,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// The module being installed may be adding new fields to existing // The module being installed may be adding new fields to existing
// entity types. Field definitions for any entity type defined by // entity types. Field definitions for any entity type defined by
// the module are handled in the if branch. // 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 ($storage_definition->getProvider() == $module) {
// If the module being installed is also defining a storage key // If the module being installed is also defining a storage key
// for the entity type, the entity schema may not exist yet. It // for the entity type, the entity schema may not exist yet. It
...@@ -390,9 +392,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { ...@@ -390,9 +392,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// Clean up all entity bundles (including fields) of every entity type // Clean up all entity bundles (including fields) of every entity type
// provided by the module that is being uninstalled. // provided by the module that is being uninstalled.
// @todo Clean this up in https://www.drupal.org/node/2350111. // @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'); $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) { if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_type_bundle_info->getBundleInfo($entity_type_id)) as $bundle) { foreach (array_keys($entity_type_bundle_info->getBundleInfo($entity_type_id)) as $bundle) {
\Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id); \Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
...@@ -419,7 +421,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { ...@@ -419,7 +421,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// opportunity to drop the corresponding database tables. // opportunity to drop the corresponding database tables.
// @todo Clean this up in https://www.drupal.org/node/2350111. // @todo Clean this up in https://www.drupal.org/node/2350111.
$update_manager = \Drupal::entityDefinitionUpdateManager(); $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) { if ($entity_type->getProvider() == $module) {
$update_manager->uninstallEntityType($entity_type); $update_manager->uninstallEntityType($entity_type);
} }
...@@ -427,7 +431,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { ...@@ -427,7 +431,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// The module being uninstalled might have added new fields to // The module being uninstalled might have added new fields to
// existing entity types. This will add them to the deleted fields // existing entity types. This will add them to the deleted fields
// repository so their data will be purged on cron. // 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) { if ($storage_definition->getProvider() == $module) {
$update_manager->uninstallFieldStorageDefinition($storage_definition); $update_manager->uninstallFieldStorageDefinition($storage_definition);
} }
......
...@@ -67,7 +67,7 @@ public function testBlockContentTypeCreation() { ...@@ -67,7 +67,7 @@ public function testBlockContentTypeCreation() {
$block_type = BlockContentType::load('foo'); $block_type = BlockContentType::load('foo');
$this->assertTrue($block_type, 'The new block type has been created.'); $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.'); $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. // Check that the block type was created in site default language.
...@@ -76,11 +76,11 @@ public function testBlockContentTypeCreation() { ...@@ -76,11 +76,11 @@ public function testBlockContentTypeCreation() {
// Create block types programmatically. // Create block types programmatically.
$this->createBlockContentType('basic', TRUE); $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->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'); $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."); $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'); $block_type = BlockContentType::load('other');
...@@ -102,7 +102,7 @@ public function testBlockContentTypeEditing() { ...@@ -102,7 +102,7 @@ public function testBlockContentTypeEditing() {
// We need two block types to prevent /block/add redirecting. // We need two block types to prevent /block/add redirecting.
$this->createBlockContentType('other'); $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.'); $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. // Verify that title and body fields are displayed.
...@@ -124,7 +124,7 @@ public function testBlockContentTypeEditing() { ...@@ -124,7 +124,7 @@ public function testBlockContentTypeEditing() {
'admin/structure/block/block-content' => 'Custom block library', 'admin/structure/block/block-content' => 'Custom block library',
'admin/structure/block/block-content/manage/basic' => 'Edit Bar', 'admin/structure/block/block-content/manage/basic' => 'Edit Bar',
]); ]);
\Drupal::entityManager()->clearCachedFieldDefinitions(); \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$this->drupalGet('block/add'); $this->drupalGet('block/add');
$this->assertRaw('Bar', 'New name was displayed.'); $this->assertRaw('Bar', 'New name was displayed.');
......
...@@ -418,7 +418,7 @@ function _comment_entity_uses_integer_id($entity_type_id) { ...@@ -418,7 +418,7 @@ function _comment_entity_uses_integer_id($entity_type_id) {
if ($entity_type_id_key === FALSE) { if ($entity_type_id_key === FALSE) {
return 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]; $entity_type_id_definition = $field_definitions[$entity_type_id_key];
return $entity_type_id_definition->getType() === 'integer'; return $entity_type_id_definition->getType() === 'integer';
} }
......
...@@ -31,8 +31,6 @@ interface CommentManagerInterface { ...@@ -31,8 +31,6 @@ interface CommentManagerInterface {
* - type: The field type. * - type: The field type.
* - bundles: The bundles in which the field appears, as an array with entity * - bundles: The bundles in which the field appears, as an array with entity
* types as keys and the array of bundle names as values. * types as keys and the array of bundle names as values.
*
* @see \Drupal\Core\Entity\EntityManagerInterface::getFieldMap()
*/ */
public function getFields($entity_type_id); public function getFields($entity_type_id);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Drupal\comment\Plugin\migrate\destination; namespace Drupal\comment\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
...@@ -47,15 +47,15 @@ class EntityComment extends EntityContentBase { ...@@ -47,15 +47,15 @@ class EntityComment extends EntityContentBase {
* The storage for this entity type. * The storage for this entity type.
* @param array $bundles * @param array $bundles
* The list of bundles this entity type has. * The list of bundles this entity type has.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity manager service. * The entity field manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager service. * The field type plugin manager service.
* @param \Drupal\Core\State\StateInterface $state * @param \Drupal\Core\State\StateInterface $state
* The state storage object. * 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) { 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_manager, $field_type_manager); parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_field_manager, $field_type_manager);
$this->state = $state; $this->state = $state;
} }
...@@ -69,9 +69,9 @@ public static function create(ContainerInterface $container, array $configuratio ...@@ -69,9 +69,9 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$migration, $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)), 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('plugin.manager.field.field_type'),
$container->get('state') $container->get('state')
); );
......
...@@ -166,8 +166,8 @@ protected function renderLink($data, ResultRow $values) { ...@@ -166,8 +166,8 @@ protected function renderLink($data, ResultRow $values) {
// reference, we arbitrarily use the first such field name we find. // reference, we arbitrarily use the first such field name we find.
// @todo Provide a means for selecting the comment field. // @todo Provide a means for selecting the comment field.
// https://www.drupal.org/node/2594201 // https://www.drupal.org/node/2594201
$entity_manager = \Drupal::entityManager(); $entity_type_manager = \Drupal::entityTypeManager();
$field_map = $entity_manager->getFieldMapByFieldType('comment'); $field_map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('comment');
$comment_field_name = 'comment'; $comment_field_name = 'comment';
foreach ($field_map['node'] as $field_name => $field_data) { foreach ($field_map['node'] as $field_name => $field_data) {
foreach ($field_data['bundles'] as $bundle_name) { foreach ($field_data['bundles'] as $bundle_name) {
...@@ -177,7 +177,7 @@ protected function renderLink($data, ResultRow $values) { ...@@ -177,7 +177,7 @@ protected function renderLink($data, ResultRow $values) {
} }
} }
} }
$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); ->getNewCommentPageNumber($this->getValue($values, 'comment_count'), $this->getValue($values), $node, $comment_field_name);
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
$this->options['alter']['url'] = $node->toUrl(); $this->options['alter']['url'] = $node->toUrl();
......
...@@ -34,10 +34,12 @@ trait CommentTestTrait { ...@@ -34,10 +34,12 @@ trait CommentTestTrait {
* Defaults to 'full'. * Defaults to 'full'.
*/ */
public function addDefaultCommentField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment', $comment_view_mode = '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'); $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. // 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 = $comment_type_storage->load($comment_type_id)) {
if ($comment_type->getTargetEntityTypeId() !== $entity_type) { 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"); 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 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com ...@@ -56,8 +58,8 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com
// Add a comment field to the host entity type. Create the field storage if // Add a comment field to the host entity type. Create the field storage if
// needed. // needed.
if (!array_key_exists($field_name, $entity_manager->getFieldStorageDefinitions($entity_type))) { if (!array_key_exists($field_name, $entity_field_manager->getFieldStorageDefinitions($entity_type))) {
$entity_manager->getStorage('field_storage_config')->create([ $entity_type_manager->getStorage('field_storage_config')->create([
'entity_type' => $entity_type, 'entity_type' => $entity_type,
'field_name' => $field_name, 'field_name' => $field_name,
'type' => 'comment', 'type' => 'comment',
...@@ -68,8 +70,8 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com ...@@ -68,8 +70,8 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com
])->save(); ])->save();
} }
// Create the field if needed, and configure its form and view displays. // Create the field if needed, and configure its form and view displays.
if (!array_key_exists($field_name, $entity_manager->getFieldDefinitions($entity_type, $bundle))) { if (!array_key_exists($field_name, $entity_field_manager->getFieldDefinitions($entity_type, $bundle))) {
$entity_manager->getStorage('field_config')->create([ $entity_type_manager->getStorage('field_config')->create([
'label' => 'Comments', 'label' => 'Comments',
'description' => '', 'description' => '',
'field_name' => $field_name, 'field_name' => $field_name,
......
...@@ -95,11 +95,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$ ...@@ -95,11 +95,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$form['#attached']['library'][] = 'content_translation/drupal.content_translation.admin'; $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'); $bundle_info_service = \Drupal::service('entity_type.bundle.info');
foreach ($form['#labels'] as $entity_type_id => $label) { foreach ($form['#labels'] as $entity_type_id => $label) {
$entity_type = $entity_manager->getDefinition($entity_type_id); $entity_type = $entity_type_manager->getDefinition($entity_type_id);
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($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); $entity_type_translatable = $content_translation_manager->isSupported($entity_type_id);
foreach ($bundle_info_service->getBundleInfo($entity_type_id) as $bundle => $bundle_info) { 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 &$ ...@@ -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) { if ($fields) {
foreach ($fields as $field_name => $definition) { 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]))) {