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) {
}
// 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)) {
......
......@@ -33,10 +33,10 @@
* 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 {
......
......@@ -157,7 +157,7 @@ protected function init() {
$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 @@ protected function getFieldDefinition($field_name) {
*/
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) {
......
......@@ -96,7 +96,7 @@ public function calculateDependencies() {
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
/**
......@@ -104,7 +104,7 @@ public function preSave(EntityStorageInterface $storage) {
*/
public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities);
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
}
/**
......
......@@ -508,12 +508,13 @@ public function getFieldMap() {
// 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) {
......
......@@ -180,6 +180,7 @@ public function createHandlerInstance($class, EntityTypeInterface $definition =
* @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 @@ public function getBaseFieldDefinitions($entity_type_id) {
* @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 @@ public function getActiveFieldStorageDefinitions($entity_type_id) {
/**
* {@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 @@ public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definiti
* @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 @@ public function getAllBundleInfo() {
/**
* {@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);
}
......
......@@ -79,10 +79,10 @@ public function getPropertyDefinitions() {
// 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);
}
}
}
......
......@@ -232,9 +232,11 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// 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 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// 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 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// 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 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// 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 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// 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);
}
......
......@@ -67,7 +67,7 @@ public function testBlockContentTypeCreation() {
$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 @@ public function testBlockContentTypeCreation() {
// 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 @@ public function testBlockContentTypeEditing() {
// 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 @@ public function testBlockContentTypeEditing() {
'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.');
......
......@@ -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';
}
......
......@@ -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);
......
......@@ -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 @@ public static function create(ContainerInterface $container, array $configuratio
$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')
);
......
......@@ -166,8 +166,8 @@ protected function renderLink($data, ResultRow $values) {
// 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 @@ 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);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['url'] = $node->toUrl();
......
......@@ -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 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com
// 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 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com
])->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,
......
......@@ -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];
}
......
......@@ -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 @@ public function testSkipUntranslatable() {
// 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 @@ public function testSkipUntranslatable() {
*/
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 @@ public function testSetTranslatable() {
// 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);
......
......@@ -103,14 +103,15 @@ public function testSettingsUI() {
'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 @@ public function testSettingsUI() {
$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 @@ public function testSettingsUI() {
$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 @@ public function testSettingsUI() {
$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.');
}
......
......@@ -404,7 +404,7 @@ public function testDatelistWidget() {
],
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Display creation form.
$this->drupalGet('entity_test/add');
......@@ -440,7 +440,7 @@ public function testDatelistWidget() {
],
])
->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 @@ public function testDatelistWidget() {
],
])
->save();
\Drupal::entityManager()->clearCachedFieldDefinitions();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
// Display creation form.
$this->drupalGet('entity_test/add');
......@@ -546,7 +546,7 @@ public function testDatelistWidget() {
],
])
->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 @@ public function testDefaultValue() {
], '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 @@ public function testDefaultValue() {
], '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 @@ public function testDefaultValue() {
$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.
......
......@@ -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) {
......
......@@ -310,7 +310,7 @@ public function preSave(EntityStorageInterface $storage) {
* 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 @@ protected function preSaveNew(EntityStorageInterface $storage) {
}
// 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 @@ protected function preSaveNew(EntityStorageInterface $storage) {
}
$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 @@ public function getColumns() {
*/
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'];
}
......
......@@ -90,7 +90,7 @@ public function testEntityReferenceDefaultValue() {
$this->assertEqual([$referenced_node->getConfigDependencyName()], $config_entity['dependencies']['content']);
// Clear field definitions cache in order to avoid stale cache values.