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 1a673bc..d3a5db3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -112,20 +112,6 @@ const FIELD_BEHAVIOR_CUSTOM = 0x0004; /** - * Load the most recent version of an entity's field data. - * - * @see field_attach_load(). - */ -const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT'; - -/** - * Load the version of an entity's field data specified in the entity. - * - * @see field_attach_load(). - */ -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..d86d7e4 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 @@ -202,6 +202,7 @@ public function query($use_groupby = FALSE) { $options += is_array($this->options['group_columns']) ? $this->options['group_columns'] : array(); $fields = array(); + // @todo: What is this? $rkey = $this->definition['is revision'] ? 'FIELD_LOAD_REVISION' : 'FIELD_LOAD_CURRENT'; // Go through the list and determine the actual column name from field api. foreach ($options as $column) { 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