class Table

Same name in this branch
  1. 11.x core/modules/views/src/Plugin/views/style/Table.php \Drupal\views\Plugin\views\style\Table
  2. 11.x core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table
Same name and namespace in other branches
  1. 10 core/modules/views/src/Plugin/views/style/Table.php \Drupal\views\Plugin\views\style\Table
  2. 10 core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table
  3. 9 core/modules/views/src/Plugin/views/style/Table.php \Drupal\views\Plugin\views\style\Table
  4. 9 core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table
  5. 8.9.x core/modules/views/src/Plugin/views/style/Table.php \Drupal\views\Plugin\views\style\Table
  6. 8.9.x core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table
  7. main core/modules/views/src/Plugin/views/style/Table.php \Drupal\views\Plugin\views\style\Table
  8. main core/lib/Drupal/Core/Render/Element/Table.php \Drupal\Core\Render\Element\Table

Describes a database table.

Hierarchy

Expanded class hierarchy of Table

6 files declare their use of Table
BatchStorage.php in core/lib/Drupal/Core/Batch/BatchStorage.php
database.api.php in core/lib/Drupal/Core/Database/database.api.php
Hooks related to the Database system and the Schema API.
locale.install in core/modules/locale/locale.install
Install, update, and uninstall functions for the Locale module.
Schema.php in core/lib/Drupal/Core/Database/Schema.php
SchemaDefinitionConversionTest.php in core/tests/Drupal/Tests/Core/Database/SchemaDefinitionConversionTest.php

... See full list

74 string references to 'Table'
ckeditor5.ckeditor5.yml in core/modules/ckeditor5/ckeditor5.ckeditor5.yml
core/modules/ckeditor5/ckeditor5.ckeditor5.yml
ckeditor5.ckeditor5.yml in core/modules/ckeditor5/ckeditor5.ckeditor5.yml
core/modules/ckeditor5/ckeditor5.ckeditor5.yml
ClaroHooks::preprocessFileWidgetMultiple in core/themes/claro/src/Hook/ClaroHooks.php
Implements hook_preprocess_HOOK() for file_widget_multiple.
editor.editor.full_html.yml in core/modules/ckeditor5/tests/fixtures/ckeditor4_config/editor.editor.full_html.yml
core/modules/ckeditor5/tests/fixtures/ckeditor4_config/editor.editor.full_html.yml
FilterHtml::tips in core/modules/filter/src/Plugin/Filter/FilterHtml.php
Generates a filter's tip.

... See full list

File

core/lib/Drupal/Core/Database/SchemaDefinition/Table.php, line 13

Namespace

Drupal\Core\Database\SchemaDefinition
View source
final class Table implements SchemaDefinitionInterface {
  
  /**
   * Constructor.
   *
   * @param string $name
   *   The table name.
   * @param ?Column[] $columns
   *   (Optional) An array that describes the table's database columns. This is
   *   normally mandatory. Some methods in the Schema API - for example
   *   Schema::addField() - require partial table definition, so this is
   *   optional to support it.
   * @param ?string $description
   *   (Optional) A string in non-markup plain text describing this table and
   *   its purpose. References to other tables should be enclosed in curly
   *   brackets.
   * @param ?PrimaryKey $primaryKey
   *   (Optional) The primary key of the table.
   * @param ?UniqueKey[] $uniqueKeys
   *   (Optional) An array of unique keys for the table.
   * @param ?Index[] $indexes
   *   (Optional) An array of indexes for the table.
   * @param ?ForeignKey[] $foreignKeys
   *   (Optional) An array of foreign keys for the table. This argument is for
   *   documentation purposes only; foreign keys are not created in the
   *   database, nor are they enforced by Drupal.
   * @param array<string,array<string,mixed>>|null $dbSpecificExtra
   *   (Optional) If you need to define a table requiring information not
   *   included elsewhere, you can specify it for each database backend.
   *   Specify this as an associative array having the database type ('mysql',
   *   'sqlite', 'pgsql', 'oracle', etc.) as the key, and an array of extra
   *   information <string,mixed> as the value.
   */
  public function __construct(public readonly string $name, public readonly ?array $columns = NULL, public readonly ?string $description = NULL, public readonly ?PrimaryKey $primaryKey = NULL, public readonly ?array $uniqueKeys = NULL, public readonly ?array $indexes = NULL, public readonly ?array $foreignKeys = NULL, public readonly ?array $dbSpecificExtra = NULL) {
    $this->validate();
  }
  
  /**
   * Validates the properties of the value object.
   *
   * @throws \Drupal\Core\Database\Exception\SchemaDefinitionException
   */
  private function validate() : void {
    if ($this->columns && !Inspector::assertAllObjects($this->columns, Column::class)) {
      throw new SchemaDefinitionException("All members of the 'columns' argument of the '{$this->name}' Table must be Column objects");
    }
    if ($this->uniqueKeys && !Inspector::assertAllObjects($this->uniqueKeys, UniqueKey::class)) {
      throw new SchemaDefinitionException("All members of the 'uniqueKeys' argument of the '{$this->name}' Table must be UniqueKey objects");
    }
    if ($this->indexes && !Inspector::assertAllObjects($this->indexes, Index::class)) {
      throw new SchemaDefinitionException("All members of the 'indexes' argument of the '{$this->name}' Table must be Index objects");
    }
    if ($this->foreignKeys && !Inspector::assertAllObjects($this->foreignKeys, ForeignKey::class)) {
      throw new SchemaDefinitionException("All members of the 'foreignKeys' argument of the '{$this->name}' Table must be ForeignKey objects");
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function toArray() : array {
    $spec = [];
    if ($this->description !== NULL) {
      $spec['description'] = $this->description;
    }
    if ($this->columns !== NULL) {
      foreach ($this->columns as $column) {
        $spec['fields'][$column->name] = $column->toArray();
      }
    }
    if ($this->primaryKey !== NULL) {
      $spec['primary key'] = $this->primaryKey
        ->toArray();
    }
    if ($this->uniqueKeys !== NULL) {
      foreach ($this->uniqueKeys as $uniqueKey) {
        $spec['unique keys'][$uniqueKey->name] = $uniqueKey->toArray();
      }
    }
    if ($this->indexes !== NULL) {
      foreach ($this->indexes as $index) {
        $spec['indexes'][$index->name] = $index->toArray();
      }
    }
    if ($this->foreignKeys !== NULL) {
      foreach ($this->foreignKeys as $foreignKey) {
        $spec['foreign keys'][$foreignKey->name] = $foreignKey->toArray();
      }
    }
    if ($this->dbSpecificExtra !== NULL) {
      foreach ($this->dbSpecificExtra as $extra) {
        foreach ($extra as $key => $value) {
          $spec[$key] = $value;
        }
      }
    }
    return $spec;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Table::toArray public function Converts the object to legacy array-based specifications. Overrides SchemaDefinitionInterface::toArray
Table::validate private function Validates the properties of the value object.
Table::__construct public function Constructor.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.