Completed
Push — 8.x-1.x ( 70f2d6...17b03a )
by Janez
02:51
created

entity_browser.views.inc::entity_browser_views_data_alter()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 31
Code Lines 19

Duplication

Lines 20
Ratio 64.52 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 19
c 1
b 0
f 1
nc 6
nop 1
dl 20
loc 31
rs 8.439
1
<?php
2
3
/**
4
 * @file
5
 * Provide views data for entity_browser.module.
6
 */
7
8
/**
9
 * Implements hook_views_data_alter().
10
 */
11
function entity_browser_views_data_alter(&$data) {
12
  $entity_manager = \Drupal::entityManager();
13
  foreach ($entity_manager->getDefinitions() as $entity_type_name => $entity_type) {
14
    if (!empty($data[$entity_type->getBaseTable()])) {
15
      $entity_keys = $entity_type->get('entity_keys');
16
17 View Code Duplication
      if ($base_table = $entity_type->getBaseTable()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
        $data[$base_table]['entity_browser_select'] = [
19
          'title' => t('Entity browser bulk select form'),
20
          'help' => t('Add a form element that lets you use a view as a base to select entities in entity browser.'),
21
          'field' => [
22
            'id' => 'entity_browser_select',
23
            'real field' => $entity_keys['id'],
24
          ],
25
        ];
26
      }
27
28 View Code Duplication
      if ($data_table = $entity_type->getDataTable()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
        $data[$data_table]['entity_browser_select'] = [
30
          'title' => t('Entity browser bulk select form'),
31
          'help' => t('Add a form element that lets you use a view as a base to select entities in entity browser.'),
32
          'field' => [
33
            'id' => 'entity_browser_select',
34
            'real field' => $entity_keys['id'],
35
          ],
36
        ];
37
      }
38
39
    }
40
  }
41
}
42