addSharedTableFieldForeignKey example

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
// The 'entity_type' and 'field_name' are required so they also need             // to be marked as NOT NULL.             $schema['fields'][$field_name]['not null'] = TRUE;
          }
          break;

        case 'created':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;

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

    return $schema;
  }

}
Home | Imprint | This part of the site doesn't use cookies.