From cc618eaee2ae86d9916fd01017af6f9901282266 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 4 Mar 2014 13:11:52 +0000
Subject: [PATCH] Issue #2180039 by damiankloip, Berdir: Vocabulary::postSave
 should not load all field entities.

---
 .../lib/Drupal/taxonomy/Entity/Vocabulary.php | 32 +++++++++++++------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php
index 6a0132a1d937..c9bf8b63fa0c 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php
@@ -9,6 +9,7 @@
 
 use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\field\Field;
 use Drupal\taxonomy\VocabularyInterface;
 
 /**
@@ -111,20 +112,31 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
     elseif ($this->getOriginalId() != $this->id()) {
       // Reflect machine name changes in the definitions of existing 'taxonomy'
       // fields.
-      $fields = entity_load_multiple('field_config');
+      $field_ids = array();
+      $field_map = Field::fieldInfo()->getFieldMap();
+      foreach ($field_map as $entity_type => $fields) {
+        foreach ($fields as $field => $info) {
+          if ($info['type'] == 'taxonomy_term_reference') {
+            $field_ids[] = $entity_type . '.' . $field;
+          }
+        }
+      }
+
+      $fields = \Drupal::entityManager()->getStorageController('field_config')->loadMultiple($field_ids);
+
       foreach ($fields as $field) {
         $update_field = FALSE;
-        if ($field->getType() == 'taxonomy_term_reference') {
-          foreach ($field->settings['allowed_values'] as &$value) {
-            if ($value['vocabulary'] == $this->getOriginalId()) {
-              $value['vocabulary'] = $this->id();
-              $update_field = TRUE;
-            }
-          }
-          if ($update_field) {
-            $field->save();
+
+        foreach ($field->settings['allowed_values'] as &$value) {
+          if ($value['vocabulary'] == $this->getOriginalId()) {
+            $value['vocabulary'] = $this->id();
+            $update_field = TRUE;
           }
         }
+
+        if ($update_field) {
+          $field->save();
+        }
       }
       // Update bundles.
       entity_invoke_bundle_hook('rename', 'taxonomy_term', $this->getOriginalId(), $this->id());
-- 
GitLab