TableMappingInterface.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace Drupal\Core\Entity\Sql;
  3. use Drupal\Core\Field\FieldStorageDefinitionInterface;
  4. /**
  5. * Provides a common interface for mapping field columns to SQL tables.
  6. *
  7. * Warning: using methods provided here should be done only when writing code
  8. * that is explicitly targeting a SQL-based entity storage. Typically this API
  9. * is used by SQL storage classes, or other SQL-specific code like the Views
  10. * integration code for the Entity SQL storage. Another example of legal usage
  11. * of this API is when needing to write a query that \Drupal::entityQuery() does
  12. * not support. Always retrieve entity identifiers and use them to load entities
  13. * instead of accessing data stored in the database directly. Any other usage
  14. * circumvents the entity system and is strongly discouraged, at least when
  15. * writing contributed code.
  16. */
  17. interface TableMappingInterface {
  18. /**
  19. * A property that represents delta used in entity query conditions.
  20. */
  21. const DELTA = '%delta';
  22. /**
  23. * Gets a list of table names for this mapping.
  24. *
  25. * @return string[]
  26. * An array of table names.
  27. */
  28. public function getTableNames();
  29. /**
  30. * Gets a list of all database columns for a given table.
  31. *
  32. * @param string $table_name
  33. * The name of the table to return the columns for.
  34. *
  35. * @return string[]
  36. * An array of database column names for this table. Both field columns and
  37. * extra columns are returned.
  38. */
  39. public function getAllColumns($table_name);
  40. /**
  41. * Gets a list of names for entity fields stored in the specified table.
  42. *
  43. * The return list is contains the entity field names, not database field
  44. * (i.e. column) names. To get the mapping of specific entity field to
  45. * database columns use ::getColumnNames().
  46. *
  47. * @param string $table_name
  48. * The name of the table to return the field names for.
  49. *
  50. * @return string[]
  51. * An array of field names for the given table.
  52. */
  53. public function getFieldNames($table_name);
  54. /**
  55. * Gets a mapping of field columns to database columns for a given field.
  56. *
  57. * @param string $field_name
  58. * The name of the entity field to return the column mapping for.
  59. *
  60. * @return string[]
  61. * The keys of this array are the keys of the array returned by
  62. * FieldStorageDefinitionInterface::getColumns() while the respective values
  63. * are the names of the database columns for this table mapping.
  64. */
  65. public function getColumnNames($field_name);
  66. /**
  67. * Gets a list of extra database columns, which store denormalized data.
  68. *
  69. * These database columns do not belong to any entity fields. Any normalized
  70. * data that is stored should be associated with an entity field.
  71. *
  72. * @param string $table_name
  73. * The name of the table to return the columns for.
  74. *
  75. * @return string[]
  76. * An array of column names for the given table.
  77. */
  78. public function getExtraColumns($table_name);
  79. /**
  80. * Gets the list of columns that can not be used as field type columns.
  81. *
  82. * @return array
  83. */
  84. public function getReservedColumns();
  85. /**
  86. * Generates a column name for a field property.
  87. *
  88. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  89. * The field storage definition.
  90. * @param string $property_name
  91. * The name of the property.
  92. *
  93. * @return string
  94. * A string containing a generated column name for a field data table that is
  95. * unique among all other fields.
  96. */
  97. public function getFieldColumnName(FieldStorageDefinitionInterface $storage_definition, $property_name);
  98. /**
  99. * Gets the table name for a given column.
  100. *
  101. * @param string $field_name
  102. * The name of the entity field to return the column mapping for.
  103. *
  104. * @return string
  105. * Table name for the given field.
  106. *
  107. * @throws \Drupal\Core\Entity\Sql\SqlContentEntityStorageException
  108. */
  109. public function getFieldTableName($field_name);
  110. }