Unverified Commit ba509afb authored by larowlan's avatar larowlan
Browse files

Issue #3047866 by mikelutz, Berdir, TR, alexpott, andypost, Satyanarayan...

Issue #3047866 by mikelutz, Berdir, TR, alexpott, andypost, Satyanarayan Reddy: Remove usage of deprecated \Drupal::entityManager() in core
parent 5ad7fe32
......@@ -1914,7 +1914,7 @@ function hook_cron() {
// Long-running operation example, leveraging a queue:
// Queue news feeds for updates once their refresh interval has elapsed.
$queue = \Drupal::queue('aggregator_feeds');
$ids = \Drupal::entityManager()->getStorage('aggregator_feed')->getFeedIdsToRefresh();
$ids = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->getFeedIdsToRefresh();
foreach (Feed::loadMultiple($ids) as $feed) {
if ($queue->createItem($feed)) {
// Add timestamp to avoid queueing item more than once.
......
......@@ -1621,7 +1621,7 @@ function install_profile_modules(&$install_state) {
*/
function install_core_entity_type_definitions() {
$update_manager = \Drupal::entityDefinitionUpdateManager();
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type) {
foreach (\Drupal::entityTypeManager()->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == 'core') {
$update_manager->installEntityType($entity_type);
}
......
......@@ -270,6 +270,7 @@ public static function currentUser() {
* correct interface or service.
*/
public static function entityManager() {
@trigger_error("\Drupal::entityManager() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager() instead in most cases. If the needed method is not on \Drupal\Core\Entity\EntityTypeManagerInterface, see the deprecated \Drupal\Core\Entity\EntityManager to find the correct interface or service. See https://www.drupal.org/node/2549139", E_USER_DEPRECATED);
return static::getContainer()->get('entity.manager');
}
......
......@@ -96,7 +96,7 @@ public static function collectRenderDisplay(FieldableEntityInterface $entity, $f
->execute();
// Load the first valid candidate display, if any.
$storage = \Drupal::entityManager()->getStorage('entity_form_display');
$storage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
foreach ($candidate_ids as $candidate_id) {
if (isset($results[$candidate_id])) {
$display = $storage->load($candidate_id);
......
......@@ -112,7 +112,7 @@ public static function collectRenderDisplays($entities, $view_mode) {
}
// Load the selected displays.
$storage = \Drupal::entityManager()->getStorage('entity_view_display');
$storage = \Drupal::entityTypeManager()->getStorage('entity_view_display');
$displays = $storage->loadMultiple($load_ids);
$displays_by_bundle = [];
......@@ -182,8 +182,8 @@ public function __construct(array $values, $entity_type) {
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// Reset the render cache for the target entity type.
parent::postSave($storage, $update);
if (\Drupal::entityManager()->hasHandler($this->targetEntityType, 'view_builder')) {
\Drupal::entityManager()->getViewBuilder($this->targetEntityType)->resetCache();
if (\Drupal::entityTypeManager()->hasHandler($this->targetEntityType, 'view_builder')) {
\Drupal::entityTypeManager()->getViewBuilder($this->targetEntityType)->resetCache();
}
}
......
......@@ -86,7 +86,7 @@ public function setTargetType($target_entity_type) {
*/
public function calculateDependencies() {
parent::calculateDependencies();
$target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType);
$target_entity_type = \Drupal::entityTypeManager()->getDefinition($this->targetEntityType);
$this->addDependency('module', $target_entity_type->getProvider());
return $this;
}
......
......@@ -22,7 +22,7 @@ abstract class EntityStorageBase extends EntityHandlerBase implements EntityStor
*
* The following code returns the same object:
* @code
* \Drupal::entityManager()->getDefinition($this->entityTypeId)
* \Drupal::entityTypeManager()->getDefinition($this->entityTypeId)
* @endcode
*
* @var \Drupal\Core\Entity\EntityTypeInterface
......
......@@ -910,7 +910,7 @@ public function getBundleConfigDependency($bundle) {
// If this entity type uses entities to manage its bundles then depend on
// the bundle entity.
if ($bundle_entity_type_id = $this->getBundleEntityType()) {
if (!$bundle_entity = \Drupal::entityManager()->getStorage($bundle_entity_type_id)->load($bundle)) {
if (!$bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type_id)->load($bundle)) {
throw new \LogicException(sprintf('Missing bundle entity, entity type %s, entity id %s.', $bundle_entity_type_id, $bundle));
}
$config_dependency = [
......
......@@ -232,7 +232,7 @@ public function getFormObject($entity_type_id, $operation) {
->setOperation($operation)
// The entity manager cannot be injected due to a circular dependency.
// @todo Remove this set call in https://www.drupal.org/node/2603542.
->setEntityManager(\Drupal::entityManager());
->setEntityManager(\Drupal::service('entity.manager'));
}
/**
......
......@@ -17,7 +17,7 @@ public function validate($entity, Constraint $constraint) {
if (isset($entity)) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if (!$entity->isNew()) {
$saved_entity = \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
$saved_entity = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
// Ensure that all the entity translations are the same as or newer
// than their current version in the storage in order to avoid
// reverting other changes. In fact the entity object that is being
......
......@@ -29,7 +29,7 @@ public function validate($value, Constraint $constraint) {
$entity = $value->getEntity();
$check_permission = TRUE;
if (!$entity->isNew()) {
$existing_entity = \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
$existing_entity = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->loadUnchanged($entity->id());
$referenced_entities = $existing_entity->{$value->getFieldDefinition()->getName()}->referencedEntities();
// Check permission if we are not already referencing the entity.
foreach ($referenced_entities as $ref) {
......
......@@ -70,7 +70,7 @@ public function getPropertyDefinitions() {
if (!isset($this->propertyDefinitions)) {
if ($entity_type_id = $this->getEntityTypeId()) {
// Return an empty array for entities that are not content entities.
$entity_type_class = \Drupal::entityManager()->getDefinition($entity_type_id)->getClass();
$entity_type_class = \Drupal::entityTypeManager()->getDefinition($entity_type_id)->getClass();
if (!in_array('Drupal\Core\Entity\FieldableEntityInterface', class_implements($entity_type_class))) {
$this->propertyDefinitions = [];
}
......
......@@ -580,7 +580,7 @@
* implementing \Drupal\Core\Entity\EntityViewBuilderInterface that you can
* retrieve with:
* @code
* $view_builder = \Drupal::entityManager()->getViewBuilder('your_entity_type');
* $view_builder = \Drupal::entityTypeManager()->getViewBuilder('your_entity_type');
* // Or if you have a $container variable:
* $view_builder = $container->get('entity.manager')->getViewBuilder('your_entity_type');
* @endcode
......@@ -1943,7 +1943,7 @@ function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\Entit
* @see \Drupal\Core\Entity\EntityManagerInterface::getFieldStorageDefinitions()
*/
function hook_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
if (\Drupal::entityManager()->getStorage($entity_type->id()) instanceof DynamicallyFieldableEntityStorageInterface) {
if (\Drupal::entityTypeManager()->getStorage($entity_type->id()) instanceof DynamicallyFieldableEntityStorageInterface) {
// Query by filtering on the ID as this is more efficient than filtering
// on the entity_type property directly.
$ids = \Drupal::entityQuery('field_storage_config')
......
......@@ -729,7 +729,7 @@ function hook_post_update_NAME(&$sandbox) {
$block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []);
$block_ids = array_keys($block_update_8001);
$block_storage = \Drupal::entityManager()->getStorage('block');
$block_storage = \Drupal::entityTypeManager()->getStorage('block');
$blocks = $block_storage->loadMultiple($block_ids);
/** @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $block) {
......
......@@ -64,7 +64,7 @@ public static function createFromBaseFieldDefinition(BaseFieldDefinition $base_f
$values = $base_field_definition->toArray();
$values['bundle'] = $bundle;
$values['baseFieldDefinition'] = $base_field_definition;
return \Drupal::entityManager()->getStorage('base_field_override')->create($values);
return \Drupal::entityTypeManager()->getStorage('base_field_override')->create($values);
}
/**
......@@ -238,7 +238,7 @@ public static function postDelete(EntityStorageInterface $storage, array $field_
* provided field name, otherwise NULL.
*/
public static function loadByName($entity_type_id, $bundle, $field_name) {
return \Drupal::entityManager()->getStorage('base_field_override')->load($entity_type_id . '.' . $bundle . '.' . $field_name);
return \Drupal::entityTypeManager()->getStorage('base_field_override')->load($entity_type_id . '.' . $bundle . '.' . $field_name);
}
/**
......
......@@ -43,7 +43,7 @@ public function referencedEntities() {
// Load and add the existing entities.
if ($ids) {
$target_type = $this->getFieldDefinition()->getSetting('target_type');
$entities = \Drupal::entityManager()->getStorage($target_type)->loadMultiple($ids);
$entities = \Drupal::entityTypeManager()->getStorage($target_type)->loadMultiple($ids);
foreach ($ids as $delta => $target_id) {
if (isset($entities[$target_id])) {
$target_entities[$delta] = $entities[$target_id];
......@@ -75,7 +75,7 @@ public static function processDefaultValue($default_value, FieldableEntityInterf
$entity_ids = \Drupal::entityQuery($target_type)
->condition('uuid', $uuids, 'IN')
->execute();
$entities = \Drupal::entityManager()
$entities = \Drupal::entityTypeManager()
->getStorage($target_type)
->loadMultiple($entity_ids);
......@@ -117,7 +117,7 @@ public function defaultValuesFormSubmit(array $element, array &$form, FormStateI
}
$ids[] = $default_value[$delta]['target_id'];
}
$entities = \Drupal::entityManager()
$entities = \Drupal::entityTypeManager()
->getStorage($this->getSetting('target_type'))
->loadMultiple($ids);
......
......@@ -184,7 +184,7 @@ public function __unset($name) {
* {@inheritdoc}
*/
public function view($display_options = []) {
$view_builder = \Drupal::entityManager()->getViewBuilder($this->getEntity()->getEntityTypeId());
$view_builder = \Drupal::entityTypeManager()->getViewBuilder($this->getEntity()->getEntityTypeId());
return $view_builder->viewFieldItem($this, $display_options);
}
......
......@@ -150,7 +150,7 @@ public function __unset($property_name) {
* {@inheritdoc}
*/
public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) {
$access_control_handler = \Drupal::entityManager()->getAccessControlHandler($this->getEntity()->getEntityTypeId());
$access_control_handler = \Drupal::entityTypeManager()->getAccessControlHandler($this->getEntity()->getEntityTypeId());
return $access_control_handler->fieldAccess($operation, $this->getFieldDefinition(), $account, $this, $return_as_object);
}
......@@ -239,7 +239,7 @@ protected function delegateMethod($method) {
* {@inheritdoc}
*/
public function view($display_options = []) {
$view_builder = \Drupal::entityManager()->getViewBuilder($this->getEntity()->getEntityTypeId());
$view_builder = \Drupal::entityTypeManager()->getViewBuilder($this->getEntity()->getEntityTypeId());
return $view_builder->viewField($this, $display_options);
}
......
......@@ -213,7 +213,7 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
// This formatter is only available for entity types that have a view
// builder.
$target_type = $field_definition->getFieldStorageDefinition()->getSetting('target_type');
return \Drupal::entityManager()->getDefinition($target_type)->hasViewBuilderClass();
return \Drupal::entityTypeManager()->getDefinition($target_type)->hasViewBuilderClass();
}
}
......@@ -136,7 +136,7 @@ public function prepareView(array $entities_items) {
}
if ($ids) {
$target_type = $this->getFieldSetting('target_type');
$target_entities = \Drupal::entityManager()->getStorage($target_type)->loadMultiple($ids);
$target_entities = \Drupal::entityTypeManager()->getStorage($target_type)->loadMultiple($ids);
}
// For each item, pre-populate the loaded entity in $item->entity, and set
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment