ViewsEntitySchemaSubscriber::dataTableAddition

protected ViewsEntitySchemaSubscriber::dataTableAddition($all_views, EntityTypeInterface $entity_type, $new_data_table, $base_table)

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.

File

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

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->entityManager->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(array &$handler_config) 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;
      }
    }
  });
}
doc_Drupal
2016-10-29 09:55:07
Comments
Leave a Comment

Please login to continue.