getBaseTable example


  protected function prepare() {
    if ($this->allRevisions) {
      if (!$base_table = $this->entityType->getRevisionTable()) {
        throw new QueryException("No revision table for " . $this->entityTypeId . ", invalid query.");
      }
    }
    else {
      if (!$base_table = $this->entityType->getBaseTable()) {
        throw new QueryException("No base table for " . $this->entityTypeId . ", invalid query.");
      }
    }
    $simple_query = TRUE;
    if ($this->entityType->getDataTable()) {
      $simple_query = FALSE;
    }
    $this->sqlQuery = $this->connection->select($base_table, 'base_table', ['conjunction' => $this->conjunction]);
    // Reset the tables structure, as it might have been built for a previous     // execution of this query.     $this->tables = NULL;
    
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;

/** * File storage for files. */
class FileStorage extends SqlContentEntityStorage implements FileStorageInterface {

  /** * {@inheritdoc} */
  public function spaceUsed($uid = NULL, $status = FileInterface::STATUS_PERMANENT) {
    $query = $this->database->select($this->entityType->getBaseTable(), 'f')
      ->condition('f.status', $status);
    $query->addExpression('SUM([f].[filesize])', 'filesize');
    if (isset($uid)) {
      $query->condition('f.uid', $uid);
    }
    return $query->execute()->fetchField();
  }

}
// Try deleting multiple test entities by deleting all.     $entities = $storage->loadMultiple();
    $storage->delete($entities);

    $all = $storage->loadMultiple();
    $this->assertEmpty($all, "All entities of type '$entity_type' should have been deleted.");

    // Verify that all data got deleted.     $definition = \Drupal::entityTypeManager()->getDefinition($entity_type);
    $connection = Database::getConnection();
    $this->assertEquals(0, (int) $connection->select($definition->getBaseTable())->countQuery()->execute()->fetchField(), 'Base table was emptied');

    if ($data_table = $definition->getDataTable()) {
      $this->assertEquals(0, (int) $connection->select($data_table)->countQuery()->execute()->fetchField(), 'Data table was emptied');
    }
    if ($revision_table = $definition->getRevisionTable()) {
      $this->assertEquals(0, (int) $connection->select($revision_table)->countQuery()->execute()->fetchField(), 'Revision table was emptied');
    }
    if ($revision_data_table = $definition->getRevisionDataTable()) {
      $this->assertEquals(0, (int) $connection->select($revision_data_table)->countQuery()->execute()->fetchField(), 'Revision data table was emptied');
    }

    

class MenuLinkContentStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@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 == $this->storage->getBaseTable()) {
      switch ($field_name) {
        case 'rediscover':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;
      }
    }

    return $schema;
  }

}

  public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    $changes = [];

    // We implement a specific logic for table updates, which is bound to the     // default sql content entity storage.     if (!$this->entityTypeManager->getStorage($entity_type->id()) instanceof SqlContentEntityStorage) {
      return;
    }

    if ($entity_type->getBaseTable() != $original->getBaseTable()) {
      $changes[] = static::BASE_TABLE_RENAME;
    }

    $revision_add = $entity_type->isRevisionable() && !$original->isRevisionable();
    $revision_remove = !$entity_type->isRevisionable() && $original->isRevisionable();
    $translation_add = $entity_type->isTranslatable() && !$original->isTranslatable();
    $translation_remove = !$entity_type->isTranslatable() && $original->isTranslatable();

    if ($revision_add) {
      $changes[] = static::REVISION_TABLE_ADDITION;
    }
    

  public function __construct(array $configuration$plugin_id$plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, MenuParentFormSelectorInterface $parent_form_selector) {
    parent::__construct($configuration$plugin_id$plugin_definition);

    $this->bundleInfoService = $bundle_info_service;
    $this->base_table = $this->definition['base_table'];

    $this->parentFormSelector = $parent_form_selector;

    $entity_types = \Drupal::entityTypeManager()->getDefinitions();
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if (in_array($this->base_table, [$entity_type->getBaseTable()$entity_type->getDataTable()$entity_type->getRevisionTable()$entity_type->getRevisionDataTable()], TRUE)) {
        $this->entityType = $entity_type;
        $this->entityTypeId = $entity_type_id;
      }
    }
  }

  /** * Gets the createdColumn property. * * @return string * The name of the column containing the created date. */

class FileStorageSchema extends SqlContentEntityStorageSchema {

  /** * {@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 == $this->storage->getBaseTable()) {
      switch ($field_name) {
        case 'status':
        case 'changed':
        case 'uri':
          $this->addSharedTableFieldIndex($storage_definition$schema, TRUE);
          break;
      }
    }
    // Entity keys automatically have not null assigned to TRUE, but for the     // file entity, NULL is a valid value for uid.     if ($field_name === 'uid') {
      
// Check that the required field definitions of a revisionable entity type     // exists and are stored in the correct tables.     $revision_key = $entity_type->getKey('revision');
    $revision_default_key = $entity_type->getRevisionMetadataKey('revision_default');
    $revision_field = $this->entityDefinitionUpdateManager->getFieldStorageDefinition($revision_key$entity_type->id());
    $revision_default_field = $this->entityDefinitionUpdateManager->getFieldStorageDefinition($revision_default_key$entity_type->id());
    $this->assertNotNull($revision_field);
    $this->assertNotNull($revision_default_field);

    $database_schema = $this->database->schema();
    $base_table = $entity_type->getBaseTable();
    $revision_table = $entity_type->getRevisionTable();
    $this->assertTrue($database_schema->tableExists($revision_table));

    $this->assertTrue($database_schema->fieldExists($base_table$revision_key));
    $this->assertTrue($database_schema->fieldExists($revision_table$revision_key));

    $this->assertFalse($database_schema->fieldExists($base_table$revision_default_key));
    $this->assertTrue($database_schema->fieldExists($revision_table$revision_default_key));

    // Also check the revision metadata keys, if they exist.     foreach (['revision_log_message', 'revision_user', 'revision_created'] as $key) {
      
$this->entityDisplayRepository = $entity_display_repository;
  }

  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    $this->entityTypeId = $this->definition['entity_type'];
    $this->entityType = $this->entityTypeManager->getDefinition($this->entityTypeId);
    $this->base_table = $this->entityType->getDataTable() ?: $this->entityType->getBaseTable();
    $this->base_field = $this->entityType->getKey('id');
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      

  protected function assertFieldAccess($entity_type_id$field_name$field_content) {
    \Drupal::state()->set('views_field_access_test-field', $field_name);

    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    $view_id = $this->randomMachineName();
    $data_table = $entity_type->getDataTable();
    // Use the data table as long as the field is not 'uuid'. This is the only     // column that can only be obtained from the base table.     $base_table = ($data_table && ($field_name !== 'uuid')) ? $data_table : $entity_type->getBaseTable();
    $entity = View::create([
      'id' => $view_id,
      'base_table' => $base_table,
      'display' => [
        'default' => [
          'display_plugin' => 'default',
          'id' => 'default',
          'display_options' => [
            'fields' => [
              $field_name => [
                'table' => $base_table,
                
/** * Defines the path_alias schema handler. */
class PathAliasStorageSchema extends SqlContentEntityStorageSchema {

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

    $schema[$this->storage->getBaseTable()]['indexes'] += [
      'path_alias__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'],
      'path_alias__path_langcode_id_status' => ['path', 'langcode', 'id', 'status'],
    ];

    return $schema;
  }

}
$revision_id_field = $table_mapping->getColumnNames($entity_type->getKey('revision'))['value'];

    $workspace_tree = $this->workspaceRepository->loadTree();
    if (isset($workspace_tree[$workspace_id])) {
      $workspace_candidates = array_merge([$workspace_id]$workspace_tree[$workspace_id]['ancestors']);
    }
    else {
      $workspace_candidates = [$workspace_id];
    }

    $query = $this->database->select($entity_type->getRevisionTable(), 'revision');
    $query->leftJoin($entity_type->getBaseTable(), 'base', "[revision].[$id_field] = [base].[$id_field]");

    $query
      ->fields('revision', [$revision_id_field$id_field])
      ->condition("revision.$workspace_field", $workspace_candidates, 'IN')
      ->where("[revision].[$revision_id_field] >= [base].[$revision_id_field]")
      ->orderBy("revision.$revision_id_field", 'ASC');

    // Restrict the result to a set of entity ID's if provided.     if ($entity_ids) {
      $query->condition("revision.$id_field", $entity_ids, 'IN');
    }

    
$label] = views_entity_field_label($entity_type_id$field_name);

  $data['file_managed'][$pseudo_field_name]['relationship'] = [
    'title' => t('@entity using @field', ['@entity' => $entity_type->getLabel(), '@field' => $label]),
    'help' => t('Relate each @entity with a @field set to the image.', ['@entity' => $entity_type->getLabel(), '@field' => $label]),
    'id' => 'entity_reverse',
    'field_name' => $field_name,
    'entity_type' => $entity_type_id,
    'field table' => $table_mapping->getDedicatedDataTableName($field_storage),
    'field field' => $field_name . '_target_id',
    'base' => $entity_type->getBaseTable(),
    'base field' => $entity_type->getKey('id'),
    'label' => $field_name,
    'join_extra' => [
      0 => [
        'field' => 'deleted',
        'value' => 0,
        'numeric' => TRUE,
      ],
    ],
  ];
}


  protected function initTableLayout() {
    // Reset table field values to ensure changes in the entity type definition     // are correctly reflected in the table layout.     $this->tableMapping = NULL;
    $this->revisionKey = NULL;
    $this->revisionTable = NULL;
    $this->dataTable = NULL;
    $this->revisionDataTable = NULL;

    $table_mapping = $this->getTableMapping();
    $this->baseTable = $table_mapping->getBaseTable();
    $revisionable = $this->entityType->isRevisionable();
    if ($revisionable) {
      $this->revisionKey = $this->entityType->getKey('revision') ?: 'revision_id';
      $this->revisionTable = $table_mapping->getRevisionTable();
    }
    $translatable = $this->entityType->isTranslatable();
    if ($translatable) {
      $this->dataTable = $table_mapping->getDataTable();
      $this->langcodeKey = $this->entityType->getKey('langcode');
      $this->defaultLangcodeKey = $this->entityType->getKey('default_langcode');
    }
    
$view_settings = $this->getConfiguration()['view'];
    $displays = Views::getApplicableViews('entity_reference_display');
    // Filter views that list the entity type we want, and group the separate     // displays by view.     $entity_type = $this->entityTypeManager->getDefinition($this->configuration['target_type']);
    $view_storage = $this->entityTypeManager->getStorage('view');

    $options = [];
    foreach ($displays as $data) {
      [$view_id$display_id] = $data;
      $view = $view_storage->load($view_id);
      if (in_array($view->get('base_table')[$entity_type->getBaseTable()$entity_type->getDataTable()])) {
        $display = $view->get('display');
        $options[$view_id . ':' . $display_id] = $view_id . ' - ' . $display[$display_id]['display_title'];
      }
    }

    // The value of the 'view_and_display' select below will need to be split     // into 'view_name' and 'view_display' in the final submitted values, so     // we massage the data at validate time on the wrapping element (not     // ideal).     $form['view']['#element_validate'] = [[static::class, 'settingsFormValidate']];

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