From 6b70606d35d2af7f72ba074117ef3927f9d9be5c Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Wed, 18 May 2016 13:03:34 +0100 Subject: [PATCH] Issue #2723567 by snehi, Ashish.Dalvi, marvin_B8, John Cook: Remove entity_load* usage for entity_view_display entity type --- core/includes/entity.inc | 2 +- .../modules/field_ui/src/Tests/ManageDisplayTest.php | 5 ++++- .../field_ui/tests/src/Kernel/EntityDisplayTest.php | 12 ++++++------ core/modules/image/src/Entity/ImageStyle.php | 7 +++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 69a07d78fa7..6d3f5729d45 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -462,7 +462,7 @@ function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $re */ function entity_get_display($entity_type, $bundle, $view_mode) { // Try loading the display from configuration. - $display = entity_load('entity_view_display', $entity_type . '.' . $bundle . '.' . $view_mode); + $display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $view_mode); // If not found, create a fresh display object. We do not preemptively create // new entity_view_display configuration entries for each existing entity type diff --git a/core/modules/field_ui/src/Tests/ManageDisplayTest.php b/core/modules/field_ui/src/Tests/ManageDisplayTest.php index f0235598c5f..4cd29016364 100644 --- a/core/modules/field_ui/src/Tests/ManageDisplayTest.php +++ b/core/modules/field_ui/src/Tests/ManageDisplayTest.php @@ -135,7 +135,10 @@ class ManageDisplayTest extends WebTestBase { $this->drupalPostForm(NULL, array(), t('Save')); \Drupal::entityManager()->clearCachedFieldDefinitions(); - $display = entity_load('entity_view_display', 'node.' . $this->type . '.default', TRUE); + $id = 'node.' . $this->type . '.default'; + $storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display'); + $storage->resetCache([$id]); + $display = $storage->load($id); $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), 'foo'); $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'The display has a dependency on field_third_party_test module.'); diff --git a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php index 711be260fe4..be188db4f1b 100644 --- a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php +++ b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php @@ -67,7 +67,7 @@ class EntityDisplayTest extends KernelTestBase { // Check that the display can be properly saved and read back. $display->save(); - $display = entity_load('entity_view_display', $display->id()); + $display = EntityViewDisplay::load($display->id()); foreach (array('component_1', 'component_2', 'component_3') as $name) { $this->assertEqual($display->getComponent($name), $expected[$name]); } @@ -95,7 +95,7 @@ class EntityDisplayTest extends KernelTestBase { // Check that the removal is correctly persisted. $display->save(); - $display = entity_load('entity_view_display', $display->id()); + $display = EntityViewDisplay::load($display->id()); $this->assertNULL($display->getComponent('component_3')); // Check that createCopy() creates a new component that can be correctly @@ -103,7 +103,7 @@ class EntityDisplayTest extends KernelTestBase { EntityViewMode::create(array('id' => $display->getTargetEntityTypeId() . '.other_view_mode', 'targetEntityType' => $display->getTargetEntityTypeId()))->save(); $new_display = $display->createCopy('other_view_mode'); $new_display->save(); - $new_display = entity_load('entity_view_display', $new_display->id()); + $new_display = EntityViewDisplay::load($new_display->id()); $dependencies = $new_display->calculateDependencies()->getDependencies(); $this->assertEqual(array('config' => array('core.entity_view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies); $this->assertEqual($new_display->getTargetEntityTypeId(), $display->getTargetEntityTypeId()); @@ -283,7 +283,7 @@ class EntityDisplayTest extends KernelTestBase { $this->assertFalse(isset($data['hidden']['test_display_non_configurable'])); // Check that defaults are correctly filled when loading the display. - $display = entity_load('entity_view_display', $display->id()); + $display = EntityViewDisplay::load($display->id()); foreach ($expected as $field_name => $options) { $this->assertEqual($display->getComponent($field_name), $options); } @@ -293,7 +293,7 @@ class EntityDisplayTest extends KernelTestBase { $data['content']['test_display_non_configurable'] = $expected['test_display_non_configurable']; $data['content']['test_display_non_configurable']['weight']++; $config->setData($data)->save(); - $display = entity_load('entity_view_display', $display->id()); + $display = EntityViewDisplay::load($display->id()); foreach ($expected as $field_name => $options) { $this->assertEqual($display->getComponent($field_name), $options); } @@ -312,7 +312,7 @@ class EntityDisplayTest extends KernelTestBase { // Delete the bundle. $type->delete(); - $display = entity_load('entity_view_display', 'node.article.default'); + $display = EntityViewDisplay::load('node.article.default'); $this->assertFalse((bool) $display); $form_display = EntityFormDisplay::load('node.article.default'); $this->assertFalse((bool) $form_display); diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 86035de945b..e5460ee352b 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -4,7 +4,6 @@ namespace Drupal\image\Entity; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityBase; -use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Routing\RequestHelper; @@ -17,7 +16,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; - +use Drupal\Core\Entity\Entity\EntityViewDisplay; /** * Defines an image style configuration entity. * @@ -138,7 +137,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity if ($style->id() != $style->getOriginalId()) { // Loop through all entity displays looking for formatters / widgets using // the image style. - foreach (entity_load_multiple('entity_view_display') as $display) { + foreach (EntityViewDisplay::loadMultiple() as $display) { foreach ($display->getComponents() as $name => $options) { if (isset($options['type']) && $options['type'] == 'image' && $options['settings']['image_style'] == $style->getOriginalId()) { $options['settings']['image_style'] = $style->id(); @@ -147,7 +146,7 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity } } } - foreach (EntityFormDisplay::loadMultiple() as $display) { + foreach (EntityViewDisplay::loadMultiple() as $display) { foreach ($display->getComponents() as $name => $options) { if (isset($options['type']) && $options['type'] == 'image_image' && $options['settings']['preview_image_style'] == $style->getOriginalId()) { $options['settings']['preview_image_style'] = $style->id();