commerce.views.inc 1.13 KB
Newer Older
1 2
<?php

3 4 5 6 7 8 9
/**
 * @file
 * Views integration for Commerce.
 */

use Drupal\Core\Entity\ContentEntityType;

10 11 12 13
/**
 * Implements hook_views_data_alter().
 */
function commerce_views_data_alter(array &$data) {
14
  // Override the bundle views handlers for commerce content entities.
15 16
  $entity_types = \Drupal::service('entity_type.manager')->getDefinitions();
  foreach ($entity_types as $entity_type) {
17
    if ($entity_type instanceof ContentEntityType && strpos($entity_type->id(), 'commerce_') === 0) {
18 19 20
      // Translatable entities have a data table. Non-translatable ones
      // (such as Order) have only a base table.
      if ($data_table = $entity_type->getDataTable()) {
21 22
        $data[$data_table][$entity_type->getKey('bundle')]['field']['id'] = 'commerce_entity_bundle';
        $data[$data_table][$entity_type->getKey('bundle')]['filter']['id'] = 'commerce_entity_bundle';
23 24
      }
      else {
25 26
        $data[$entity_type->getBaseTable()][$entity_type->getKey('bundle')]['field']['id'] = 'commerce_entity_bundle';
        $data[$entity_type->getBaseTable()][$entity_type->getKey('bundle')]['filter']['id'] = 'commerce_entity_bundle';
27 28 29 30
      }
    }
  }
}