Version 1
[yaffs-website] / web / core / modules / field_ui / tests / modules / field_ui_test / field_ui_test.module
1 <?php
2
3 /**
4  * @file
5  * Field UI test module.
6  */
7
8 use Drupal\Core\Access\AccessResult;
9 use Drupal\Core\Form\FormStateInterface;
10 use Drupal\Core\Render\Element;
11 use Drupal\Core\Field\FieldConfigInterface;
12
13 /**
14  * Implements hook_ENTITY_TYPE_access().
15  */
16 function field_ui_test_field_config_access(FieldConfigInterface $field) {
17   return AccessResult::forbiddenIf($field->getName() == 'highlander');
18 }
19
20 /**
21  * Implements hook_form_FORM_BASE_ID_alter().
22  */
23 function field_ui_test_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) {
24   $table = &$form['fields'];
25
26   foreach (Element::children($table) as $name) {
27     $table[$name]['parent_wrapper']['parent']['#options'] = ['indent' => 'Indent'];
28     $table[$name]['parent_wrapper']['parent']['#default_value'] = 'indent';
29   }
30
31   $table['indent'] = [
32     '#attributes' => ['class' => ['draggable', 'field-group'], 'id' => 'indent-id'],
33     '#row_type' => 'group',
34     '#region_callback' => 'field_ui_test_region_callback',
35     '#js_settings' => ['rowHandler' => 'group'],
36     'human_name' => [
37       '#markup' => 'Indent',
38       '#prefix' => '<span class="group-label">',
39       '#suffix' => '</span>',
40     ],
41     'weight' => [
42       '#type' => 'textfield',
43       '#default_value' => 0,
44       '#size' => 3,
45       '#attributes' => ['class' => ['field-weight']],
46     ],
47     'parent_wrapper' => [
48       'parent' => [
49         '#type' => 'select',
50         '#options' => ['indent' => 'Indent'],
51         '#empty_value' => '',
52         '#default_value' => '',
53         '#attributes' => ['class' => ['field-parent']],
54         '#parents' => ['fields', 'indent', 'parent'],
55       ],
56       'hidden_name' => [
57         '#type' => 'hidden',
58         '#default_value' => 'indent',
59         '#attributes' => ['class' => ['field-name']],
60       ],
61     ],
62   ];
63
64 }
65
66 function field_ui_test_region_callback($row) {
67   return 'content';
68 }