diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index b21958b..e8f322b 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -1330,22 +1330,7 @@ public function onFieldPurge(FieldConfigInterface $field) { } /** - * Gets the SQL table schema. - * - * @private Calling this function circumvents the entity system and is - * strongly discouraged. This function is not considered part of the public - * API and modules relying on it might break even in minor releases. - * - * @param \Drupal\field\FieldConfigInterface $field - * The field object - * @param array $schema - * The field schema array. Mandatory for upgrades, omit otherwise. - * - * @return array - * The same as a hook_schema() implementation for the data and the - * revision tables. - * - * @see hook_schema() + * {@inhertidoc} */ public static function _fieldSqlSchema(FieldConfigInterface $field, array $schema = NULL) { if ($field->deleted) { @@ -1496,21 +1481,7 @@ public static function _fieldSqlSchema(FieldConfigInterface $field, array $schem } /** - * Generates a table name for a field data table. - * - * @private Calling this function circumvents the entity system and is - * strongly discouraged. This function is not considered part of the public - * API and modules relying on it might break even in minor releases. Only - * call this function to write a query that \Drupal::entityQuery() does not - * support. Always call entity_load() before using the data found in the - * table. - * - * @param \Drupal\field\FieldConfigInterface $field - * The field object. - * - * @return string - * A string containing the generated name for the database table. - * + * {@inheritdoc} */ static public function _fieldTableName(FieldConfigInterface $field) { if ($field->deleted) { @@ -1526,20 +1497,7 @@ static public function _fieldTableName(FieldConfigInterface $field) { } /** - * Generates a table name for a field revision archive table. - * - * @private Calling this function circumvents the entity system and is - * strongly discouraged. This function is not considered part of the public - * API and modules relying on it might break even in minor releases. Only - * call this function to write a query that \Drupal::entityQuery() does not - * support. Always call entity_load() before using the data found in the - * table. - * - * @param \Drupal\field\FieldConfigInterface $field - * The field object. - * - * @return string - * A string containing the generated name for the database table. + * {@inheritdoc} */ static public function _fieldRevisionTableName(FieldConfigInterface $field) { if ($field->deleted) { @@ -1555,6 +1513,20 @@ static public function _fieldRevisionTableName(FieldConfigInterface $field) { } /** + * {@inheritdoc} + */ + static public function _fieldIndexName(FieldConfigInterface $field, $index) { + return $field->getName() . '_' . $index; + } + + /** + * {@inheritdoc} + */ + static public function _fieldColumnName(FieldConfigInterface $field, $column) { + return in_array($column, FieldConfig::getReservedColumns()) ? $column : $field->getName() . '_' . $column; + } + + /** * Generates a safe and unanbiguous field table name. * * The method accounts for a maximum table name length of 64 characters, and @@ -1585,47 +1557,4 @@ static protected function _generateFieldTableName(FieldConfigInterface $field, $ return $table_name; } - /** - * Generates an index name for a field data table. - * - * @private Calling this function circumvents the entity system and is - * strongly discouraged. This function is not considered part of the public - * API and modules relying on it might break even in minor releases. - * - * @param \Drupal\field\FieldConfigInterface $field - * The field structure - * @param string $index - * The name of the index. - * - * @return string - * A string containing a generated index name for a field data table that is - * unique among all other fields. - */ - static public function _fieldIndexName(FieldConfigInterface $field, $index) { - return $field->getName() . '_' . $index; - } - - /** - * Generates a column name for a field data table. - * - * @private Calling this function circumvents the entity system and is - * strongly discouraged. This function is not considered part of the public - * API and modules relying on it might break even in minor releases. Only - * call this function to write a query that \Drupal::entityQuery() does not - * support. Always call entity_load() before using the data found in the - * table. - * - * @param \Drupal\field\FieldConfigInterface $field - * The field object. - * @param string $column - * The name of the column. - * - * @return string - * A string containing a generated column name for a field data table that is - * unique among all other fields. - */ - static public function _fieldColumnName(FieldConfigInterface $field, $column) { - return in_array($column, FieldConfig::getReservedColumns()) ? $column : $field->getName() . '_' . $column; - } - } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php b/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php index 8c4e3d8..1a94bc6 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlEntityStorageInterface.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\Schema\EntitySchemaProviderInterface; +use Drupal\field\FieldConfigInterface; /** * A common interface for SQL-based storage controllers. @@ -23,4 +24,99 @@ */ public function getTableMapping(); + /** + * Gets the SQL table schema. + * + * @private Calling this function circumvents the entity system and is + * strongly discouraged. This function is not considered part of the public + * API and modules relying on it might break even in minor releases. + * + * @param \Drupal\field\FieldConfigInterface $field + * The field object + * @param array $schema + * The field schema array. Mandatory for upgrades, omit otherwise. + * + * @return array + * The same as a hook_schema() implementation for the data and the + * revision tables. + * + * @see hook_schema() + */ + public static function _fieldSqlSchema(FieldConfigInterface $field, array $schema = NULL); + + /** + * Generates a table name for a field data table. + * + * @private Calling this function circumvents the entity system and is + * strongly discouraged. This function is not considered part of the public + * API and modules relying on it might break even in minor releases. Only + * call this function to write a query that \Drupal::entityQuery() does not + * support. Always call entity_load() before using the data found in the + * table. + * + * @param \Drupal\field\FieldConfigInterface $field + * The field object. + * + * @return string + * A string containing the generated name for the database table. + */ + static public function _fieldTableName(FieldConfigInterface $field); + + /** + * Generates a table name for a field revision archive table. + * + * @private Calling this function circumvents the entity system and is + * strongly discouraged. This function is not considered part of the public + * API and modules relying on it might break even in minor releases. Only + * call this function to write a query that \Drupal::entityQuery() does not + * support. Always call entity_load() before using the data found in the + * table. + * + * @param \Drupal\field\FieldConfigInterface $field + * The field object. + * + * @return string + * A string containing the generated name for the database table. + */ + static public function _fieldRevisionTableName(FieldConfigInterface $field); + + /** + * Generates an index name for a field data table. + * + * @private Calling this function circumvents the entity system and is + * strongly discouraged. This function is not considered part of the public + * API and modules relying on it might break even in minor releases. + * + * @param \Drupal\field\FieldConfigInterface $field + * The field structure + * @param string $index + * The name of the index. + * + * @return string + * A string containing a generated index name for a field data table that is + * unique among all other fields. + */ + static public function _fieldIndexName(FieldConfigInterface $field, $index); + + /** + * Generates a column name for a field data table. + * + * @private Calling this function circumvents the entity system and is + * strongly discouraged. This function is not considered part of the public + * API and modules relying on it might break even in minor releases. Only + * call this function to write a query that \Drupal::entityQuery() does not + * support. Always call entity_load() before using the data found in the + * table. + * + * @param \Drupal\field\FieldConfigInterface $field + * The field object. + * @param string $column + * The name of the column. + * + * @return string + * A string containing a generated column name for a field data table that is + * unique among all other fields. + */ + static public function _fieldColumnName(FieldConfigInterface $field, $column); + } diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index f74e97c..32f1f9e 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -6,7 +6,7 @@ */ use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Entity\ContentEntityDatabaseStorage; +use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\field\FieldConfigInterface; use Drupal\field\FieldInstanceConfigInterface; @@ -64,11 +64,11 @@ function field_views_data_alter(&$data) { * The field definition. * * @return bool - * True if the entity type uses ContentEntityDatabaseStorage. + * True if the entity type uses SqlStorageControllerInterface. */ function _field_views_is_sql_entity_type(FieldConfigInterface $field) { $entity_manager = \Drupal::entityManager(); - return $entity_manager->hasDefinition($field->entity_type) && $entity_manager->getStorage($field->entity_type) instanceof ContentEntityDatabaseStorage; + return $entity_manager->hasDefinition($field->entity_type) && $entity_manager->getStorage($field->entity_type) instanceof SqlEntityStorageInterface; } /** @@ -141,13 +141,13 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { // Description of the field tables. $field_tables = array( EntityStorageInterface::FIELD_LOAD_CURRENT => array( - 'table' => ContentEntityDatabaseStorage::_fieldTableName($field), + 'table' => call_user_func(array($entity_type->getStorageClass(), '_fieldTableName') ,$field), 'alias' => "{$entity_type_id}__{$field_name}", ), ); if ($supports_revisions) { $field_tables[EntityStorageInterface::FIELD_LOAD_REVISION] = array( - 'table' => ContentEntityDatabaseStorage::_fieldRevisionTableName($field), + 'table' => call_user_func(array($entity_type->getStorageClass(), '_fieldRevisionTableName') ,$field), 'alias' => "{$entity_type_id}_revision__{$field_name}", ); } @@ -178,7 +178,7 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { // Build the list of additional fields to add to queries. $add_fields = array('delta', 'langcode', 'bundle'); foreach (array_keys($field_columns) as $column) { - $add_fields[] = ContentEntityDatabaseStorage::_fieldColumnName($field, $column); + $add_fields[] = call_user_func(array($entity_type->getStorageClass(), '_fieldColumnName') ,$field, $column); } // Determine the label to use for the field. We don't have a label available // at the field level, so we just go through all instances and take the one @@ -302,10 +302,10 @@ function field_views_field_default_views_data(FieldConfigInterface $field) { else { $group = t('@group (historical data)', array('@group' => $group_name)); } - $column_real_name = ContentEntityDatabaseStorage::_fieldColumnName($field, $column); + $column_real_name = call_user_func(array($entity_type->getStorageClass(), '_fieldColumnName') ,$field, $column); // Load all the fields from the table by default. - $field_sql_schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field); + $field_sql_schema = call_user_func(array($entity_type->getStorageClass(), '_fieldSqlSchema') ,$field); $additional_fields = array_keys($field_sql_schema[$table]['fields']); $data[$table_alias][$column_real_name] = array(