Commit cc618eae authored by alexpott's avatar alexpott

Issue #2180039 by damiankloip, Berdir: Vocabulary::postSave should not load all field entities.

parent 31dfc6fe
......@@ -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());
......
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