diff --git a/core/modules/field_ui/src/Element/FieldUiTable.php b/core/modules/field_ui/src/Element/FieldUiTable.php index 8c80baa95ea2fb2108147c9076de427bd804f1ee..1dd5e62840f7b52a75a50a636137b3b7da917aaf 100644 --- a/core/modules/field_ui/src/Element/FieldUiTable.php +++ b/core/modules/field_ui/src/Element/FieldUiTable.php @@ -85,11 +85,12 @@ public static function tablePreRender($elements) { if ($depth = count($parents[$name])) { $children = Element::children($row); $cell = current($children); - $row[$cell]['#prefix'] = [ + $indentation = [ '#theme' => 'indentation', '#size' => $depth, '#suffix' => isset($row[$cell]['#prefix']) ? $row[$cell]['#prefix'] : '', ]; + $row[$cell]['#prefix'] = \Drupal::service('renderer')->render($indentation); } // Add row id and associate JS settings. diff --git a/core/modules/field_ui/src/Tests/FieldUIIndentationTest.php b/core/modules/field_ui/src/Tests/FieldUIIndentationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6b9ad7eb6350efedf5536f47e9c90cf64a5a78cc --- /dev/null +++ b/core/modules/field_ui/src/Tests/FieldUIIndentationTest.php @@ -0,0 +1,45 @@ +<?php + +/** + * @file + * Contains \Drupal\field_ui\Tests\FieldUIIndentationTest. + */ + +namespace Drupal\field_ui\Tests; + +use Drupal\simpletest\WebTestBase; + +/** + * Tests indentation on Field UI. + * + * @group field_ui + */ +class FieldUIIndentationTest extends WebTestBase { + + /** + * Modules to install. + * + * @var array + */ + public static $modules = array('node', 'field_ui', 'field_ui_test'); + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + // Create a test user. + $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node display')); + $this->drupalLogin($admin_user); + + // Create Basic page node type. + $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + + } + + function testIndentation() { + $this->drupalGet('admin/structure/types/manage/page/display'); + $this->assertRaw('js-indentation indentation'); + } +} diff --git a/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..aa8a97a43815deff1416cddeb3193bc2c15119eb --- /dev/null +++ b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml @@ -0,0 +1,6 @@ +name: 'Field UI test' +type: module +description: 'Support module for Field UI tests.' +core: 8.x +package: Testing +version: VERSION diff --git a/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module new file mode 100644 index 0000000000000000000000000000000000000000..562168fac550973f7a4f47c04d16ee4df98d18fd --- /dev/null +++ b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module @@ -0,0 +1,59 @@ +<?php + +/** + * @file + * Field UI test module. + */ + +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Element; + +/** + * 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'] = array('indent' => 'Indent'); + $table[$name]['parent_wrapper']['parent']['#default_value'] = 'indent'; + } + + $table['indent'] = [ + '#attributes' => array('class' => array('draggable', 'field-group'), 'id' => 'indent-id'), + '#row_type' => 'group', + '#region_callback' => 'field_ui_test_region_callback', + '#js_settings' => array('rowHandler' => 'group'), + 'human_name' => array( + '#markup' => 'Indent', + '#prefix' => '<span class="group-label">', + '#suffix' => '</span>', + ), + 'weight' => array( + '#type' => 'textfield', + '#default_value' => 0, + '#size' => 3, + '#attributes' => array('class' => array('field-weight')), + ), + 'parent_wrapper' => array( + 'parent' => array( + '#type' => 'select', + '#options' => array('indent' => 'Indent'), + '#empty_value' => '', + '#default_value' => '', + '#attributes' => array('class' => array('field-parent')), + '#parents' => array('fields', 'indent', 'parent'), + ), + 'hidden_name' => array( + '#type' => 'hidden', + '#default_value' => 'indent', + '#attributes' => array('class' => array('field-name')), + ), + ), + ]; + +} + +function field_ui_test_region_callback($row) { + return 'content'; +}