ac45bb5d1ef408a78f306bcbc3975f87b2417aca
[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     $schema['node_field_data']['indexes'] += [
21       'node__frontpage' => ['promote', 'status', 'sticky', 'created'],
22       'node__title_type' => ['title', ['type', 4]],
23     ];
24
25     return $schema;
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
32     $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
33     $field_name = $storage_definition->getName();
34
35     if ($table_name == 'node_revision') {
36       switch ($field_name) {
37         case 'langcode':
38           $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
39           break;
40
41         case 'revision_uid':
42           $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');
43           break;
44       }
45     }
46
47     if ($table_name == 'node_field_data') {
48       switch ($field_name) {
49         case 'promote':
50         case 'status':
51         case 'sticky':
52         case 'title':
53           // Improves the performance of the indexes defined
54           // in getEntitySchema().
55           $schema['fields'][$field_name]['not null'] = TRUE;
56           break;
57
58         case 'changed':
59         case 'created':
60           // @todo Revisit index definitions:
61           //   https://www.drupal.org/node/2015277.
62           $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
63           break;
64       }
65     }
66
67     return $schema;
68   }
69
70 }