entity_browser.api.php ➔ hook_entity_browser_display_info_alter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file
5
 * Hooks related to entity browser and it's plugins.
6
 */
7
8
/**
9
 * @addtogroup hooks
10
 * @{
11
 */
12
13
/**
14
 * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserDisplay.
15
 *
16
 * @param array $displays
17
 *   The array of display plugins, keyed on the machine-readable name.
18
 */
19
function hook_entity_browser_display_info_alter(array &$displays) {
20
  $displays['modal_display']['label'] = t('Superb fancy stuff!');
21
}
22
23
/**
24
 * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserWidget.
25
 *
26
 * @param array $widgets
27
 *   The array of widget plugins, keyed on the machine-readable name.
28
 */
29
function hook_entity_browser_widget_info_alter(array &$widgets) {
30
  $widgets['view_widget']['label'] = t('Views FTW!');
31
}
32
33
/**
34
 * Alter the information provided in \Drupal\entity_browser\Annotation\SelectionDisplay.
35
 *
36
 * @param array $selection_displays
37
 *   The array of selection display plugins, keyed on the machine-readable name.
38
 */
39
function hook_entity_browser_selection_display_info_alter(array &$selection_displays) {
40
  $selection_displays['no_selection']['label'] = t('Nothing!');
41
}
42
43
/**
44
 * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserWidgetSelector.
45
 *
46
 * @param array $widget_selectors
47
 *   The array of widget selector plugins, keyed on the machine-readable name.
48
 */
49
function hook_entity_browser_widget_selector_info_alter(array &$widget_selectors) {
0 ignored issues
show
Unused Code introduced by
The parameter $widget_selectors is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
  $widgets['tab_selector']['label'] = t('Tabs are for winners');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$widgets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $widgets = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
51
}
52
53
/**
54
 * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserFieldWidgetDisplay.
55
 *
56
 * @param array $field_displays
57
 *   The array of field widget display plugins, keyed on the machine-readable
58
 *   name.
59
 */
60
function hook_entity_browser_field_widget_display_info_alter(array &$field_displays) {
61
  $field_displays['rendered_entity']['label'] = t('Entity render system FTW');
62
}
63
64
/**
65
 * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserWidgetValidation.
66
 *
67
 * @param array $validation_plugins
68
 *   The array of widget validation plugins, keyed on the machine-readable
69
 *   name.
70
 */
71
function hook_entity_browser_widget_validation_info_alter(array &$validation_plugins) {
0 ignored issues
show
Unused Code introduced by
The parameter $validation_plugins is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
  $field_displays['not_null']['label'] = t('Not null fabulous validator');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$field_displays was never initialized. Although not strictly required by PHP, it is generally a good practice to add $field_displays = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
73
}
74
75
/**
76
 * @} End of "addtogroup hooks".
77
 */
78