forked from drupalcommerce/commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommerce.module
More file actions
59 lines (53 loc) · 1.67 KB
/
Copy pathcommerce.module
File metadata and controls
59 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* @file
* Defines common functionality for all Commerce modules.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_toolbar().
*/
function commerce_toolbar() {
$items = [];
$items['commerce'] = [
'#type' => 'toolbar_item',
'#attached' => [
'library' => [
'commerce/drupal.commerce.toolbar',
],
],
];
return $items;
}
/**
* Implements hook_field_widget_form_alter().
*
* Base fields have a description that's used for two very different purposes:
* - To describe the field in the Views UI and other parts of the system.
* - As user-facing help text shown on field widgets.
* The text is rarely suitable for both, and in most cases feels redundant
* as user-facing help text. Hence we remove it from that context, but only if
* the definition didn't specify otherwise via our display_description setting.
*/
function commerce_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
$field_definition = $context['items']->getFieldDefinition();
if (!($field_definition instanceof \Drupal\Core\Field\BaseFieldDefinition)) {
// Not a base field.
return;
}
if (strpos($field_definition->getTargetEntityTypeId(), 'commerce_') !== 0) {
// Not a Commerce entity type.
return;
}
if ($field_definition->getSetting('display_description')) {
// The definition requested that the description stays untouched.
return;
}
$element['#description'] = '';
// Many widgets are nested one level deeper.
$children = \Drupal\Core\Render\Element::getVisibleChildren($element);
if (count($children) == 1) {
$child = reset($children);
$element[$child]['#description'] = '';
}
}