protected function DateRecurOccurrences::createOccurrenceTable in Recurring Dates Field 3.x
Same name and namespace in other branches
- 8.2 src/DateRecurOccurrences.php \Drupal\date_recur\DateRecurOccurrences::createOccurrenceTable()
- 3.0.x src/DateRecurOccurrences.php \Drupal\date_recur\DateRecurOccurrences::createOccurrenceTable()
- 3.1.x src/DateRecurOccurrences.php \Drupal\date_recur\DateRecurOccurrences::createOccurrenceTable()
Creates an occurrence table.
Parameters
\Drupal\Core\Field\FieldStorageDefinitionInterface $fieldDefinition: The field definition.
1 call to DateRecurOccurrences::createOccurrenceTable()
- DateRecurOccurrences::fieldStorageCreate in src/
DateRecurOccurrences.php - Reacts to field creation.
File
- src/
DateRecurOccurrences.php, line 297
Class
- DateRecurOccurrences
- Manages occurrences tables and the data that populates them.
Namespace
Drupal\date_recurCode
protected function createOccurrenceTable(FieldStorageDefinitionInterface $fieldDefinition) : void {
$entityTypeId = $fieldDefinition
->getTargetEntityTypeId();
$entityType = $this->entityTypeManager
->getDefinition($entityTypeId);
$fieldName = $fieldDefinition
->getName();
$entityFieldDefinitions = $this->entityFieldManager
->getFieldStorageDefinitions($entityTypeId);
// Logic taken from field tables: see \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::getDedicatedTableSchema.
$idDefinition = $entityFieldDefinitions[$entityType
->getKey('id')];
if ($idDefinition
->getType() === 'integer') {
$fields['entity_id'] = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The entity id this data is attached to',
];
}
else {
$fields['entity_id'] = [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'description' => 'The entity id this data is attached to',
];
}
if ($entityType
->isRevisionable()) {
$revisionDefinition = $entityFieldDefinitions[$entityType
->getKey('revision')];
if ($revisionDefinition
->getType() === 'integer') {
$fields['revision_id'] = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The entity revision id this data is attached to',
];
}
else {
$fields['revision_id'] = [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'description' => 'The entity revision id this data is attached to',
];
}
}
$fields['field_delta'] = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The sequence number for this data item, used for multi-value fields',
];
$fields['delta'] = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The sequence number in generated occurrences for the RRULE',
];
$fieldSchema = $fieldDefinition
->getSchema();
$fields[$fieldName . '_value'] = $fieldSchema['columns']['value'];
$fields[$fieldName . '_end_value'] = $fieldSchema['columns']['end_value'];
$schema = [
'description' => sprintf('Occurrences cache for %s.%s', $fieldDefinition
->getTargetEntityTypeId(), $fieldName),
'fields' => $fields,
'indexes' => [
'value' => [
'entity_id',
$fieldName . '_value',
],
],
];
$tableName = DateRecurOccurrences::getOccurrenceCacheStorageTableName($fieldDefinition);
$this->database
->schema()
->createTable($tableName, $schema);
}