diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 744eb23..c016093 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -351,7 +351,7 @@ protected function buildQuery($ids, $revision_id = FALSE) { protected function attachLoad(&$queried_entities, $load_revision = FALSE) { // Attach field values. if ($this->entityInfo['fieldable']) { - $this->loadFieldItems($queried_entities, $load_revision ? FIELD_LOAD_REVISION : FIELD_LOAD_CURRENT); + $this->loadFieldItems($queried_entities, $load_revision ? static::FIELD_LOAD_REVISION : static::FIELD_LOAD_CURRENT); } // Call hook_entity_load(). @@ -550,7 +550,7 @@ public function getQueryServiceName() { * {@inheritdoc} */ protected function doLoadFieldItems($entities, $age) { - $load_current = $age == FIELD_LOAD_CURRENT; + $load_current = $age == static::FIELD_LOAD_CURRENT; // Collect entities ids and bundles. $bundles = array(); diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php index 7d3c5a2..c7f72f7 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php @@ -21,6 +21,16 @@ interface EntityStorageControllerInterface { /** + * Load the most recent version of an entity's field data. + */ + const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT'; + + /** + * Load the version of an entity's field data specified in the entity. + */ + const FIELD_LOAD_REVISION = 'FIELD_LOAD_REVISION'; + + /** * Resets the internal, static entity cache. * * @param $ids diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php index 4911694..5ee2309 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php @@ -26,8 +26,10 @@ * @param array $entities * An array of entities keyed by entity ID. * @param int $age - * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or - * FIELD_LOAD_REVISION to load the version indicated by each entity. + * EntityStorageControllerInterface::FIELD_LOAD_CURRENT to load the most + * recent revision for all fields, or + * EntityStorageControllerInterface::FIELD_LOAD_REVISION to load the version + * indicated by each entity. */ protected function loadFieldItems(array $entities, $age) { if (empty($entities)) { @@ -36,7 +38,7 @@ protected function loadFieldItems(array $entities, $age) { // Only the most current revision of non-deleted fields for cacheable entity // types can be cached. - $load_current = $age == FIELD_LOAD_CURRENT; + $load_current = $age == static::FIELD_LOAD_CURRENT; $info = entity_get_info($this->entityType); $use_cache = $load_current && $info['field_cache']; @@ -165,8 +167,10 @@ protected function deleteFieldItemsRevision(EntityInterface $entity) { * @param array $entities * An array of entities keyed by entity ID. * @param int $age - * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or - * FIELD_LOAD_REVISION to load the version indicated by each entity. + * EntityStorageControllerInterface::FIELD_LOAD_CURRENT to load the most + * recent revision for all fields, or + * EntityStorageControllerInterface::FIELD_LOAD_REVISION to load the version + * indicated by each entity. */ abstract protected function doLoadFieldItems($entities, $age); diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index a6f0723..d3b7b66 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity\Query; use Drupal\Core\Database\Query\PagerSelectExtender; +use Drupal\Core\Entity\EntityStorageControllerInterface; /** * The base entity query class. @@ -101,11 +102,12 @@ /** * Flag indicating whether to query the current revision or all revisions. * - * Can be either FIELD_LOAD_CURRENT or FIELD_LOAD_REVISION. + * Can be either EntityStorageControllerInterface::FIELD_LOAD_CURRENT or + * EntityStorageControllerInterface::FIELD_LOAD_REVISION. * * @var string */ - protected $age = FIELD_LOAD_CURRENT; + protected $age = EntityStorageControllerInterface::FIELD_LOAD_CURRENT; /** * The query pager data. @@ -232,7 +234,7 @@ public function accessCheck($access_check = TRUE) { /** * Implements \Drupal\Core\Entity\Query\QueryInterface::age(). */ - public function age($age = FIELD_LOAD_CURRENT) { + public function age($age = EntityStorageControllerInterface::FIELD_LOAD_CURRENT) { $this->age = $age; return $this; } diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php index c82a3da..3a02e8e 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity\Query; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Database\Query\AlterableInterface; /** @@ -158,13 +159,15 @@ public function accessCheck($access_check = TRUE); * @TODO: Once revision tables have been cleaned up, revisit this. * * @param $age - * - FIELD_LOAD_CURRENT (default): Query the most recent revisions only, - * - FIELD_LOAD_REVISION: Query all revisions. + * - EntityStorageControllerInterface::FIELD_LOAD_CURRENT (default): Query + * the most recent revisions only, + * - EntityStorageControllerInterface::FIELD_LOAD_REVISION: Query all + * revisions. * * @return \Drupal\Core\Entity\Query\QueryInterface * The called object. */ - public function age($age = FIELD_LOAD_CURRENT); + public function age($age = EntityStorageControllerInterface::FIELD_LOAD_CURRENT); /** * Execute the query. diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index e72a586..80ad70a 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity\Query\Sql; use Drupal\Core\Database\Query\SelectInterface; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Entity\Plugin\DataType\EntityReference; use Drupal\Core\Entity\Query\QueryException; @@ -82,7 +83,7 @@ public function addField($field, $type, $langcode) { for ($key = 0; $key <= $count; $key ++) { // If there is revision support and only the current revision is being // queried then use the revision id. Otherwise, the entity id will do. - if (!empty($entity_info['entity_keys']['revision']) && $age == FIELD_LOAD_CURRENT) { + if (!empty($entity_info['entity_keys']['revision']) && $age == EntityStorageControllerInterface::FIELD_LOAD_CURRENT) { // This contains the relevant SQL field to be used when joining entity // tables. $entity_id_field = $entity_info['entity_keys']['revision']; @@ -251,7 +252,7 @@ protected function ensureEntityTable($index_prefix, $property, $type, $langcode, protected function ensureFieldTable($index_prefix, &$field, $type, $langcode, $base_table, $entity_id_field, $field_id_field) { $field_name = $field['field_name']; if (!isset($this->fieldTables[$index_prefix . $field_name])) { - $table = $this->sqlQuery->getMetaData('age') == FIELD_LOAD_CURRENT ? DatabaseStorageController::_fieldTableName($field) : DatabaseStorageController::_fieldRevisionTableName($field); + $table = $this->sqlQuery->getMetaData('age') == EntityStorageControllerInterface::FIELD_LOAD_CURRENT ? DatabaseStorageController::_fieldTableName($field) : DatabaseStorageController::_fieldRevisionTableName($field); if ($field['cardinality'] != 1) { $this->sqlQuery->addMetaData('simple_query', FALSE); } diff --git a/core/modules/block/tests/lib/Drupal/block/Tests/BlockFormControllerTest.php b/core/modules/block/tests/lib/Drupal/block/Tests/BlockFormControllerTest.php index c1677c5..d3d2146 100644 --- a/core/modules/block/tests/lib/Drupal/block/Tests/BlockFormControllerTest.php +++ b/core/modules/block/tests/lib/Drupal/block/Tests/BlockFormControllerTest.php @@ -15,11 +15,6 @@ define('BLOCK_REGION_NONE', -1); } -// @todo Remove once the constants are replaced with constants on classes. -if (!defined('FIELD_LOAD_CURRENT')) { - define('FIELD_LOAD_CURRENT', 'FIELD_LOAD_CURRENT'); -} - /** * Tests the block form controller. * diff --git a/core/modules/field/field.module b/core/modules/field/field.module index dabe6e7..33b4cb0 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -108,16 +108,6 @@ const FIELD_BEHAVIOR_CUSTOM = 0x0004; /** - * Load the most recent version of an entity's field data. - */ -const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT'; - -/** - * Load the version of an entity's field data specified in the entity. - */ -const FIELD_LOAD_REVISION = 'FIELD_LOAD_REVISION'; - -/** * Implements hook_help(). */ function field_help($path, $arg) { diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index 7e24b44..d6d9e97 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\DatabaseStorageController; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\field\FieldInterface; /** @@ -144,20 +145,20 @@ function field_views_field_default_views_data(FieldInterface $field) { // Description of the field tables. $field_tables = array( - FIELD_LOAD_CURRENT => array( + EntityStorageControllerInterface::FIELD_LOAD_CURRENT => array( 'table' => DatabaseStorageController::_fieldTableName($field), 'alias' => "{$entity_type}__{$field->name}", ), ); if ($supports_revisions) { - $field_tables[FIELD_LOAD_REVISION] = array( + $field_tables[EntityStorageControllerInterface::FIELD_LOAD_REVISION] = array( 'table' => DatabaseStorageController::_fieldRevisionTableName($field), 'alias' => "{$entity_type}_revision__{$field->name}", ); } // Build the relationships between the field table and the entity tables. - $table_alias = $field_tables[FIELD_LOAD_CURRENT]['alias']; + $table_alias = $field_tables[EntityStorageControllerInterface::FIELD_LOAD_CURRENT]['alias']; $data[$table_alias]['table']['join'][$entity_table] = array( 'left_field' => $entity_info['entity_keys']['id'], 'field' => 'entity_id', @@ -166,7 +167,7 @@ function field_views_field_default_views_data(FieldInterface $field) { ), ); if ($supports_revisions) { - $table_alias = $field_tables[FIELD_LOAD_REVISION]['alias']; + $table_alias = $field_tables[EntityStorageControllerInterface::FIELD_LOAD_REVISION]['alias']; $data[$table_alias]['table']['join'][$entity_revision_table] = array( 'left_field' => $entity_info['entity_keys']['revision'], 'field' => 'revision_id', @@ -195,7 +196,7 @@ function field_views_field_default_views_data(FieldInterface $field) { $table = $table_info['table']; $table_alias = $table_info['alias']; - if ($type == FIELD_LOAD_CURRENT) { + if ($type == EntityStorageControllerInterface::FIELD_LOAD_CURRENT) { $group = $group_name; $field_alias = $field_name; } @@ -216,7 +217,7 @@ function field_views_field_default_views_data(FieldInterface $field) { $aliases = array(); $also_known = array(); foreach ($all_labels as $label_name => $true) { - if ($type == FIELD_LOAD_CURRENT) { + if ($type == EntityStorageControllerInterface::FIELD_LOAD_CURRENT) { if ($label != $label_name) { $aliases[] = array( 'base' => $entity_table, @@ -255,7 +256,7 @@ function field_views_field_default_views_data(FieldInterface $field) { 'entity_tables' => $entity_tables, // Default the element type to div, let the UI change it if necessary. 'element type' => 'div', - 'is revision' => $type == FIELD_LOAD_REVISION, + 'is revision' => $type == EntityStorageControllerInterface::FIELD_LOAD_REVISION, ); } @@ -301,7 +302,7 @@ function field_views_field_default_views_data(FieldInterface $field) { $table = $table_info['table']; $table_alias = $table_info['alias']; - if ($type == FIELD_LOAD_CURRENT) { + if ($type == EntityStorageControllerInterface::FIELD_LOAD_CURRENT) { $group = $group_name; } else { diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 7c7e032..f84ca11 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -8,6 +8,7 @@ namespace Drupal\field\Plugin\field\field_type; use Drupal\Core\Entity\Field\PrepareCacheInterface; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase; use Drupal\field\FieldInterface; @@ -100,7 +101,7 @@ public function prepareCache() { array($entity_id => $this->getInstance()), $langcode, &$items, - FIELD_LOAD_CURRENT, + EntityStorageControllerInterface::FIELD_LOAD_CURRENT, ); call_user_func_array($callback, $args); $this->setValue($items[$entity_id][0]); diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 6f09d6f..ea74a94 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Language\Language; use Drupal\field\Plugin\Type\Formatter\FormatterPluginManager; use Drupal\views\ViewExecutable; @@ -202,7 +203,7 @@ public function query($use_groupby = FALSE) { $options += is_array($this->options['group_columns']) ? $this->options['group_columns'] : array(); $fields = array(); - $rkey = $this->definition['is revision'] ? 'FIELD_LOAD_REVISION' : 'FIELD_LOAD_CURRENT'; + $rkey = $this->definition['is revision'] ? EntityStorageControllerInterface::FIELD_LOAD_REVISION : EntityStorageControllerInterface::FIELD_LOAD_CURRENT; // Go through the list and determine the actual column name from field api. foreach ($options as $column) { $name = $column; diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 538d121..625375d 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -7,11 +7,9 @@ use Drupal\file\Entity\File; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Template\Attribute; -use Symfony\Component\HttpFoundation\JsonResponse; use Drupal\file\FileUsage\FileUsageInterface; -use Drupal\Core\Ajax\AjaxResponse; -use Drupal\Core\Ajax\ReplaceCommand; // Load all Field module hooks for File. require_once __DIR__ . '/file.field.inc'; @@ -621,7 +619,7 @@ function file_file_download($uri, $field_type = 'file') { } // Find out which (if any) fields of this type contain the file. - $references = file_get_file_references($file, NULL, FIELD_LOAD_CURRENT, $field_type); + $references = file_get_file_references($file, NULL, EntityStorageControllerInterface::FIELD_LOAD_CURRENT, $field_type); // Stop processing if there are no references in order to avoid returning // headers for files controlled by other modules. Make an exception for @@ -1827,8 +1825,10 @@ function file_icon_map(File $file) { * reference check to the given field. * @param $age * (optional) A constant that specifies which references to count. Use - * FIELD_LOAD_REVISION to retrieve all references within all revisions or - * FIELD_LOAD_CURRENT to retrieve references only in the current revisions. + * EntityStorageControllerInterface::FIELD_LOAD_REVISION to retrieve all + * references within all revisions or + * EntityStorageControllerInterface::FIELD_LOAD_CURRENT to retrieve references + * only in the current revisions. * @param $field_type * (optional) The name of a field type. If given, limits the reference check * to fields of the given type. If both $field and $field_type is given but @@ -1839,7 +1839,7 @@ function file_icon_map(File $file) { * A multidimensional array. The keys are field_name, entity_type, * entity_id and the value is an entity referencing this file. */ -function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file') { +function file_get_file_references(File $file, $field = NULL, $age = EntityStorageControllerInterface::FIELD_LOAD_REVISION, $field_type = 'file') { $references = &drupal_static(__FUNCTION__, array()); $field_columns = &drupal_static(__FUNCTION__ . ':field_columns', array()); @@ -1853,7 +1853,7 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R // The usage table contains usage of every revision. If we are looking // for every revision or the entity does not support revisions then // every usage is already a match. - $match_entity_type = $age == FIELD_LOAD_REVISION || !isset($entity_info['entity_keys']['revision']); + $match_entity_type = $age == EntityStorageControllerInterface::FIELD_LOAD_REVISION || !isset($entity_info['entity_keys']['revision']); $entities = entity_load_multiple($entity_type, array_keys($entity_ids)); foreach ($entities as $entity) { $bundle = $entity->bundle(); diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index 0c4d52d..1360af3 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -45,10 +45,10 @@ protected function attachLoad(&$queried_entities, $load_revision = FALSE) { } if ($load_revision) { - $this->loadFieldItems($queried_entities, FIELD_LOAD_REVISION); + $this->loadFieldItems($queried_entities, static::FIELD_LOAD_REVISION); } else { - $this->loadFieldItems($queried_entities, FIELD_LOAD_CURRENT); + $this->loadFieldItems($queried_entities, static::FIELD_LOAD_CURRENT); } // Besides the list of nodes, pass one additional argument to diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index e1b0ea7..166d615 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Entity; +use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Language\Language; /** @@ -250,7 +251,7 @@ function testEntityQuery() { $this->assertResult(); $this->queryResults = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'merhaba') - ->age(FIELD_LOAD_REVISION) + ->age(EntityStorageControllerInterface::FIELD_LOAD_REVISION) ->sort('revision_id') ->execute(); // Bit 2 needs to be set. @@ -280,7 +281,7 @@ function testEntityQuery() { $this->assertIdentical($results, array_slice($assert, 4, 8, TRUE)); $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'a', 'ENDS_WITH') - ->age(FIELD_LOAD_REVISION) + ->age(EntityStorageControllerInterface::FIELD_LOAD_REVISION) ->sort('id') ->execute(); // Now we get everything.