public function TableConfig::createTable in Data 8
Create data table.
Parameters
array $table_definition:
Return value
mixed
Overrides TableConfigInterface::createTable
1 call to TableConfig::createTable()
- TableConfig::save in src/
Entity/ TableConfig.php - Saves an entity permanently.
File
- src/
Entity/ TableConfig.php, line 56
Class
- TableConfig
- Defines the Data Table entity.
Namespace
Drupal\data\EntityCode
public function createTable() {
$table_definition = array(
'description' => t('Automatically created by data module on @time', array(
'@time' => date('Y/m/d H:i', Drupal::time()
->getRequestTime()),
)),
'fields' => array(),
);
$primary_keys = array();
foreach ($this->table_schema as $field) {
$table_definition['fields'][$field['name']] = array(
'description' => $field['label'],
'type' => $field['type'],
'size' => $field['size'],
'unsigned' => $field['unsigned'],
);
if ($field['length']) {
$table_definition['fields'][$field['name']]['length'] = $field['length'];
}
if ($field['primary']) {
$primary_keys[] = $field['name'];
}
}
// @todo: non-primary index definition.
if ($primary_keys) {
$table_definition['primary key'] = $primary_keys;
}
Database::getConnection()
->schema()
->createTable($this
->id(), $table_definition);
}