Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / src / NodeStorageSchema.php
1 <?php
2
3 namespace Drupal\node;
4
5 use Drupal\Core\Entity\ContentEntityTypeInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
8
9 /**
10  * Defines the node schema handler.
11  */
12 class NodeStorageSchema extends SqlContentEntityStorageSchema {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
18     $schema = parent::getEntitySchema($entity_type, $reset);
19
20     if ($data_table = $this->storage->getDataTable()) {
21       $schema[$data_table]['indexes'] += [
22         'node__frontpage' => ['promote', 'status', 'sticky', 'created'],
23         'node__title_type' => ['title', ['type', 4]],
24       ];
25     }
26
27     return $schema;
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
34     $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
35     $field_name = $storage_definition->getName();
36
37     if ($table_name == 'node_revision') {
38       switch ($field_name) {
39         case 'langcode':
40           $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
41           break;
42
43         case 'revision_uid':
44           $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');
45           break;
46       }
47     }
48
49     if ($table_name == 'node_field_data') {
50       switch ($field_name) {
51         case 'promote':
52         case 'status':
53         case 'sticky':
54         case 'title':
55           // Improves the performance of the indexes defined
56           // in getEntitySchema().
57           $schema['fields'][$field_name]['not null'] = TRUE;
58           break;
59
60         case 'changed':
61         case 'created':
62           // @todo Revisit index definitions:
63           //   https://www.drupal.org/node/2015277.
64           $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
65           break;
66       }
67     }
68
69     return $schema;
70   }
71
72 }