field_ui_test.module 1.8 KB

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