diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index b75e9bd76db76461ddc598a8793f202bdb4c6324..29c1de96a280e186ab1b61e970d8877bded0beea 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -9,7 +9,6 @@ use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; -use Drupal\Core\Field\PrepareCacheInterface; use Drupal\field\FieldConfigInterface; use Drupal\field\FieldInstanceConfigInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -151,17 +150,7 @@ protected function loadFieldItems(array $entities) { $translation = $entity->getTranslation($langcode); foreach ($translation as $field_name => $items) { if ($items->getFieldDefinition() instanceof FieldInstanceConfigInterface && !$items->isEmpty()) { - foreach ($items as $delta => $item) { - // If the field item needs to prepare the cache data, call the - // corresponding method, otherwise use the values as cache - // data. - if ($item instanceof PrepareCacheInterface) { - $data[$langcode][$field_name][$delta] = $item->getCacheData(); - } - else { - $data[$langcode][$field_name][$delta] = $item->getValue(); - } - } + $data[$langcode][$field_name] = $items->getValue(); } } } diff --git a/core/lib/Drupal/Core/Field/PrepareCacheInterface.php b/core/lib/Drupal/Core/Field/PrepareCacheInterface.php deleted file mode 100644 index 85d558ccbbe5f43383227b1b75b2ff38b86171be..0000000000000000000000000000000000000000 --- a/core/lib/Drupal/Core/Field/PrepareCacheInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Core\Field\PrepareCacheInterface. - */ - -namespace Drupal\Core\Field; - -/** - * Interface for preparing field values before they enter cache. - * - * If a field type implements this interface, this method will be used instead - * of the regular getValue() to collect the data to include in the cache of - * field values. - */ -interface PrepareCacheInterface { - - /** - * Returns the data to store in the field cache. - * - * This method is called if the entity type has field caching enabled, when an - * entity is loaded and no existing cache entry was found in the field cache. - * - * This method should never trigger the loading of fieldable entities, since - * this is likely to cause infinite recursions. A common workaround is to - * provide a base formatter class implementing the prepareView() method - * instead. - * - * The recommended way to implement it is to provide a computed field item - * property that can accepts setting a value through setValue(). See - * \Drupal\text\Plugin\Field\FieldType\TextItemBase and the corresponding - * computed property Drupal\text\TextProcessed for an example. - */ - public function getCacheData(); - -} diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php index d3478156fa057b0c6782ec38825cd8c60723f878..e3669de43834e4b9dd722f823998f2b16cc2a9c5 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php @@ -8,7 +8,6 @@ namespace Drupal\datetime\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\Field\PrepareCacheInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; @@ -24,7 +23,7 @@ * list_class = "\Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList" * ) */ -class DateTimeItem extends FieldItemBase implements PrepareCacheInterface { +class DateTimeItem extends FieldItemBase { /** * {@inheritdoc} @@ -101,21 +100,6 @@ public function settingsForm(array $form, array &$form_state, $has_data) { return $element; } - /** - * {@inheritdoc} - */ - public function getCacheData() { - $data = $this->getValue(); - // The function generates a Date object for each field early so that it is - // cached in the field cache. This avoids the need to generate the object - // later. The date will be retrieved in UTC, the local timezone adjustment - // must be made in real time, based on the preferences of the site and user. - if (!empty($data['value'])) { - $data['date'] = $this->date; - } - return $data; - } - /** * {@inheritdoc} */ diff --git a/core/modules/field/src/Tests/FieldAttachStorageTest.php b/core/modules/field/src/Tests/FieldAttachStorageTest.php index 0bf773286fb591a2488f7a1e30dfd1bf3d75060c..ec805f2e67ecb4dcae111f5aea74ad3f015d35f1 100644 --- a/core/modules/field/src/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/src/Tests/FieldAttachStorageTest.php @@ -51,11 +51,6 @@ function testFieldAttachSaveLoad() { $this->createFieldWithInstance('', $entity_type); $cardinality = $this->field->getCardinality(); - // Configure the instance so that we test - // \Drupal\field_test\Plugin\Field\FieldType\TestItem::getCacheData(). - $this->instance->settings['test_cached_data'] = TRUE; - $this->instance->save(); - // TODO : test empty values filtering and "compression" (store consecutive deltas). // Preparation: create three revisions and store them in $revision array. $values = array(); @@ -80,10 +75,6 @@ function testFieldAttachSaveLoad() { for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. $this->assertEqual($entity->{$this->field_name}[$delta]->value , $values[$current_revision][$delta]['value'], format_string('Current revision: expected value %delta was found.', array('%delta' => $delta))); - // The value added in - // \Drupal\field_test\Plugin\Field\FieldType\TestItem::getCacheData() is - // found. - $this->assertEqual($entity->{$this->field_name}[$delta]->additional_key, 'additional_value', format_string('Current revision: extra information for value %delta was found', array('%delta' => $delta))); } // Confirm each revision loads the correct data. @@ -134,11 +125,6 @@ function testFieldAttachLoadMultiple() { 'field_name' => $field_names[$i], 'entity_type' => $entity_type, 'bundle' => $bundles[$bundle], - // Configure the instance so that we test - // \Drupal\field_test\Plugin\Field\FieldType\TestItem::getCacheData(). - 'settings' => array( - 'test_cached_data' => TRUE, - ), ))->save(); } } @@ -169,8 +155,6 @@ function testFieldAttachLoadMultiple() { } // The field value loaded matches the one inserted. $this->assertEqual($entity->{$field_name}->value, $values[$index][$field_name], format_string('Entity %index: expected value was found.', array('%index' => $index))); - // The value added in hook_field_load() is found. - $this->assertEqual($entity->{$field_name}->additional_key, 'additional_value', format_string('Entity %index: extra information was found', array('%index' => $index))); } } } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php index fcc599c575b5412716eecc7e7ac7049f94079bad..e215833f540dfd4c37912355626f5bc492f933d4 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php @@ -8,7 +8,6 @@ namespace Drupal\field_test\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\Field\PrepareCacheInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; @@ -23,7 +22,7 @@ * default_formatter = "field_test_default" * ) */ -class TestItem extends FieldItemBase implements PrepareCacheInterface { +class TestItem extends FieldItemBase { /** * {@inheritdoc} @@ -104,20 +103,6 @@ public function instanceSettingsForm(array $form, array &$form_state) { return $form; } - /** - * {@inheritdoc} - */ - public function getCacheData() { - // To keep the test non-intrusive, only act for instances with the - // 'test_cached_data' setting explicitly set to TRUE. Also don't add - // anything on empty values. - if ($this->getSetting('test_cached_data') && !$this->isEmpty()) { - // Set the additional value so that getValue() will return it. - $this->additional_key = 'additional_value'; - } - return $this->getValue(); - } - /** * {@inheritdoc} */ diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php index 4f2deca27e8e24c47029420685c138c5860d03b7..b225acec67bab09c6099eb54965e26f5697ea1af 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php @@ -9,13 +9,12 @@ use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\Field\PrepareCacheInterface; use Drupal\Core\TypedData\DataDefinition; /** * Base class for 'text' configurable field types. */ -abstract class TextItemBase extends FieldItemBase implements PrepareCacheInterface { +abstract class TextItemBase extends FieldItemBase { /** * {@inheritdoc} @@ -64,26 +63,6 @@ public function isEmpty() { return $value === NULL || $value === ''; } - /** - * {@inheritdoc} - */ - public function getCacheData() { - $data = $this->getValue(); - // Where possible, generate the processed (sanitized) version of each - // textual property (e.g., 'value', 'summary') within this field item early - // so that it is cached in the field cache. This avoids the need to look up - // the sanitized value in the filter cache separately. - $text_processing = $this->getSetting('text_processing'); - if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { - foreach ($this->definition->getPropertyDefinitions() as $property => $definition) { - if ($definition->getClass() == '\Drupal\text\TextProcessed') { - $data[$property] = $this->get($property)->getValue(); - } - } - } - return $data; - } - /** * {@inheritdoc} */ diff --git a/core/modules/text/src/Tests/TextWithSummaryItemTest.php b/core/modules/text/src/Tests/TextWithSummaryItemTest.php index 9b930953263f6d34ca54c53cc888f0824d4e59c2..68a6179a0d33fd9db0c6a943d5cdbda0e080b45c 100644 --- a/core/modules/text/src/Tests/TextWithSummaryItemTest.php +++ b/core/modules/text/src/Tests/TextWithSummaryItemTest.php @@ -102,71 +102,6 @@ public function testCrudAndUpdate() { $this->assertEqual($entity->summary_field->summary_processed, $summary); } - /** - * Tests that the processed values are cached. - */ - function testProcessedCache() { - // Use an entity type that has caching enabled. - $entity_type = 'entity_test_rev'; - - $this->createField($entity_type); - - // Create an entity with a summary and a text format. - $entity = entity_create($entity_type); - $entity->summary_field->value = $value = $this->randomName(); - $entity->summary_field->summary = $summary = $this->randomName(); - $entity->summary_field->format = 'plain_text'; - $entity->name->value = $this->randomName(); - $entity->save(); - - // Check that the processed values are correctly computed. - $this->assertEqual($entity->summary_field->processed, $value); - $this->assertEqual($entity->summary_field->summary_processed, $summary); - - // Load the entity and check that the field cache contains the expected - // data. - $entity = entity_load($entity_type, $entity->id()); - $cache = \Drupal::cache('entity')->get("field:$entity_type:" . $entity->id()); - $this->assertEqual($cache->data, array( - Language::LANGCODE_NOT_SPECIFIED => array( - 'summary_field' => array( - 0 => array( - 'value' => $value, - 'summary' => $summary, - 'format' => 'plain_text', - 'processed' => $value, - 'summary_processed' => $summary, - ), - ), - ), - )); - - // Inject fake processed values into the cache to make sure that these are - // used as-is and not re-calculated when the entity is loaded. - $data = array( - Language::LANGCODE_NOT_SPECIFIED => array( - 'summary_field' => array( - 0 => array( - 'value' => $value, - 'summary' => $summary, - 'format' => 'plain_text', - 'processed' => 'Cached processed value', - 'summary_processed' => 'Cached summary processed value', - ), - ), - ), - ); - \Drupal::cache('entity')->set("field:$entity_type:" . $entity->id(), $data); - $entity = entity_load($entity_type, $entity->id(), TRUE); - $this->assertEqual($entity->summary_field->processed, 'Cached processed value'); - $this->assertEqual($entity->summary_field->summary_processed, 'Cached summary processed value'); - - // Change the format, this should update the processed properties. - $entity->summary_field->format = 'no_filters'; - $this->assertEqual($entity->summary_field->processed, $value); - $this->assertEqual($entity->summary_field->summary_processed, $summary); - } - /** * Creates a text_with_summary field and field instance. * diff --git a/core/modules/text/text.module b/core/modules/text/text.module index e6196765160f56bd6b82286c2ea06eff1e829038..623f14bb0a7c5523c1f90e48ee5c74c9aa07e82f 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -158,20 +158,6 @@ function text_summary($text, $format = NULL, $size = NULL) { return $summary; } -/** - * Implements hook_filter_format_update(). - */ -function text_filter_format_update($format) { - \Drupal::entityManager()->clearCachedFieldDefinitions(); -} - -/** - * Implements hook_filter_format_disable(). - */ -function text_filter_format_disable($format) { - \Drupal::entityManager()->clearCachedFieldDefinitions(); -} - /** * Implements hook_field_formatter_info_alter(). */