NodeStorageSchema.php 1.94 KB
Newer Older
1 2 3 4 5
<?php

namespace Drupal\node;

use Drupal\Core\Entity\ContentEntityTypeInterface;
6
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
7
use Drupal\Core\Field\FieldStorageDefinitionInterface;
8 9 10 11 12 13 14 15 16 17 18 19

/**
 * Defines the node schema handler.
 */
class NodeStorageSchema extends SqlContentEntityStorageSchema {

  /**
   * {@inheritdoc}
   */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type, $reset);

20 21 22 23
    $schema['node_field_data']['indexes'] += [
      'node__frontpage' => ['promote', 'status', 'sticky', 'created'],
      'node__title_type' => ['title', ['type', 4]],
    ];
24 25 26 27

    return $schema;
  }

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  /**
   * {@inheritdoc}
   */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
    $field_name = $storage_definition->getName();

    if ($table_name == 'node_revision') {
      switch ($field_name) {
        case 'langcode':
          $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
          break;

        case 'revision_uid':
          $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');
          break;
      }
    }

    if ($table_name == 'node_field_data') {
      switch ($field_name) {
        case 'promote':
        case 'status':
        case 'sticky':
        case 'title':
          // Improves the performance of the indexes defined
          // in getEntitySchema().
          $schema['fields'][$field_name]['not null'] = TRUE;
          break;

        case 'changed':
        case 'created':
60 61
          // @todo Revisit index definitions:
          //   https://www.drupal.org/node/2015277.
62 63 64 65 66 67 68 69
          $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
          break;
      }
    }

    return $schema;
  }

70
}