function ViewsEntitySchemaSubscriber::dataTableAddition

Same name and namespace in other branches
  1. 9 core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber::dataTableAddition()
  2. 10 core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber::dataTableAddition()
  3. 11.x core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber::dataTableAddition()

Updates views if a data table is added.

Parameters

\Drupal\views\Entity\View[] $all_views: All views.

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

string $new_data_table: The new data table.

string $base_table: The base table.

1 call to ViewsEntitySchemaSubscriber::dataTableAddition()
ViewsEntitySchemaSubscriber::onEntityTypeUpdate in core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php
Reacts to the update of the entity type.

File

core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php, line 366

Class

ViewsEntitySchemaSubscriber
Reacts to changes on entity types to update all views entities.

Namespace

Drupal\views\EventSubscriber

Code

protected function dataTableAddition($all_views, EntityTypeInterface $entity_type, $new_data_table, $base_table) {
    
    /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage */
    $entity_type_id = $entity_type->id();
    $storage = $this->entityTypeManager
        ->getStorage($entity_type_id);
    $storage->setEntityType($entity_type);
    $table_mapping = $storage->getTableMapping();
    $data_table_fields = $table_mapping->getFieldNames($new_data_table);
    $base_table_fields = $table_mapping->getFieldNames($base_table);
    $data_table = $new_data_table;
    $this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $base_table, $data_table, $base_table_fields, $data_table_fields) {
        if (isset($handler_config['entity_type']) && isset($handler_config['entity_field']) && $handler_config['entity_type'] == $entity_type_id) {
            // Move all fields which just exists on the data table.
            if ($handler_config['table'] == $base_table && in_array($handler_config['entity_field'], $data_table_fields) && !in_array($handler_config['entity_field'], $base_table_fields)) {
                $handler_config['table'] = $data_table;
                $view->set('_updated', TRUE);
            }
        }
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.