field_ui_test.module

Same filename in other branches
  1. 8.9.x core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module
  2. 10 core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module
  3. 11.x core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module

Field UI test module.

File

core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module

View source
<?php


/**
 * @file
 * Field UI test module.
 */
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Field\FieldConfigInterface;

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function field_ui_test_field_config_access(FieldConfigInterface $field) {
    return AccessResult::forbiddenIf($field->getName() == 'highlander');
}

/**
 * Implements hook_form_FORM_BASE_ID_alter().
 */
function field_ui_test_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) {
    $table =& $form['fields'];
    foreach (Element::children($table) as $name) {
        $table[$name]['parent_wrapper']['parent']['#options'] = [
            'indent' => 'Indent',
        ];
        $table[$name]['parent_wrapper']['parent']['#default_value'] = 'indent';
    }
    $table['indent'] = [
        '#attributes' => [
            'class' => [
                'draggable',
                'field-group',
            ],
            'id' => 'indent-id',
        ],
        '#row_type' => 'group',
        '#region_callback' => 'field_ui_test_region_callback',
        '#js_settings' => [
            'rowHandler' => 'group',
        ],
        'human_name' => [
            '#markup' => 'Indent',
            '#prefix' => '<span class="group-label">',
            '#suffix' => '</span>',
        ],
        'weight' => [
            '#type' => 'textfield',
            '#default_value' => 0,
            '#size' => 3,
            '#attributes' => [
                'class' => [
                    'field-weight',
                ],
            ],
        ],
        'parent_wrapper' => [
            'parent' => [
                '#type' => 'select',
                '#options' => [
                    'indent' => 'Indent',
                ],
                '#empty_value' => '',
                '#default_value' => '',
                '#attributes' => [
                    'class' => [
                        'field-parent',
                    ],
                ],
                '#parents' => [
                    'fields',
                    'indent',
                    'parent',
                ],
            ],
            'hidden_name' => [
                '#type' => 'hidden',
                '#default_value' => 'indent',
                '#attributes' => [
                    'class' => [
                        'field-name',
                    ],
                ],
            ],
        ],
    ];
}
function field_ui_test_region_callback($row) {
    return 'content';
}

Functions

Title Deprecated Summary
field_ui_test_field_config_access Implements hook_ENTITY_TYPE_access().
field_ui_test_form_entity_view_display_edit_form_alter Implements hook_form_FORM_BASE_ID_alter().
field_ui_test_region_callback

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.