diff -u b/core/modules/field_ui/src/Element/FieldUiTable.php b/core/modules/field_ui/src/Element/FieldUiTable.php --- b/core/modules/field_ui/src/Element/FieldUiTable.php +++ b/core/modules/field_ui/src/Element/FieldUiTable.php @@ -22,13 +22,11 @@ * {@inheritdoc} */ public function getInfo() { - $class = get_class($this); $info = parent::getInfo(); $info['#regions'] = ['' => []]; $info['#theme'] = 'field_ui_table'; // Prepend FieldUiTable's prerender. - // $info['#pre_render'][] = [$class, 'tablePreRender']; - array_unshift($info['#pre_render'], [$class, 'tablePreRender']); + array_unshift($info['#pre_render'], [$this, 'tablePreRender']); return $info; } @@ -43,6 +41,7 @@ * $options array. * * @return array + * The $element with prepared variables ready for field-ui-table.html.twig. * * @see drupal_render() * @see \Drupal\Core\Render\Element\Table::preRenderTable() @@ -54,10 +53,10 @@ // data contained in the flat form structure, to determine row order and // indentation. $regions = $elements['#regions']; - $tree = array('' => array('name' => '', 'children' => array())); + $tree = ['' => ['name' => '', 'children' => []]]; $trees = array_fill_keys(array_keys($regions), $tree); - $parents = array(); + $parents = []; $children = Element::children($elements); $list = array_combine($children, $children); @@ -69,7 +68,7 @@ // Proceed if parent is known. if (empty($parent) || isset($parents[$parent])) { // Grab parent, and remove the row from the next iteration. - $parents[$name] = $parent ? array_merge($parents[$parent], array($parent)) : array(); + $parents[$name] = $parent ? array_merge($parents[$parent], [$parent]) : []; unset($list[$name]); // Determine the region for the row. @@ -80,28 +79,28 @@ foreach ($parents[$name] as $key) { $target = &$target['children'][$key]; } - $target['children'][$name] = array('name' => $name, 'weight' => $row['weight']['#value']); + $target['children'][$name] = ['name' => $name, 'weight' => $row['weight']['#value']]; // Add tabledrag indentation to the first row cell. if ($depth = count($parents[$name])) { $children = Element::children($row); $cell = current($children); - $indentation = array( + $row[$cell]['#prefix'] = [ '#theme' => 'indentation', '#size' => $depth, - ); - $row[$cell]['#prefix'] = drupal_render($indentation) . (isset($row[$cell]['#prefix']) ? $row[$cell]['#prefix'] : ''); + '#suffix' => isset($row[$cell]['#prefix']) ? $row[$cell]['#prefix'] : '', + ]; } // Add row id and associate JS settings. $id = Html::getClass($name); $row['#attributes']['id'] = $id; if (isset($row['#js_settings'])) { - $row['#js_settings'] += array( + $row['#js_settings'] += [ 'rowHandler' => $row['#row_type'], 'name' => $name, 'region' => $region_name, - ); + ]; $js_settings[$id] = $row['#js_settings']; } } @@ -110,7 +109,7 @@ // Determine rendering order from the tree structure. foreach ($regions as $region_name => $region) { - $elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], array('Drupal\field_ui\Element\FieldUiTable', 'reduceOrder')); + $elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], [static::class, 'reduceOrder']); } $elements['#attached']['drupalSettings']['fieldUIRowsData'] = $js_settings; @@ -144,30 +143,36 @@ // Add region rows. if (isset($region['title']) && empty($region['invisible'])) { - $elements['#rows'][] = array( - 'class' => array('region-title', 'region-' . $region_name_class . '-title'), + $elements['#rows'][] = [ + 'class' => [ + 'region-title', + 'region-' . $region_name_class . '-title' + ], 'no_striping' => TRUE, - 'data' => array( - array('data' => $region['title'], 'colspan' => $columns_count), - ), - ); + 'data' => [ + ['data' => $region['title'], 'colspan' => $columns_count], + ], + ]; } if (isset($region['message'])) { $class = (empty($region['rows_order']) ? 'region-empty' : 'region-populated'); - $elements['#rows'][] = array( - 'class' => array('region-message', 'region-' . $region_name_class . '-message', $class), + $elements['#rows'][] = [ + 'class' => [ + 'region-message', + 'region-' . $region_name_class . '-message', $class, + ], 'no_striping' => TRUE, - 'data' => array( - array('data' => $region['message'], 'colspan' => $columns_count), - ), - ); + 'data' => [ + ['data' => $region['message'], 'colspan' => $columns_count], + ], + ]; } // Add form rows, in the order determined at pre-render time. foreach ($region['rows_order'] as $name) { $element = $rows[$name]; - $row = array('data' => array()); + $row = ['data' => []]; if (isset($element['#attributes'])) { $row += $element['#attributes']; } @@ -177,7 +182,7 @@ $child = $element[$cell_key]; // Do not render a cell for children of #type 'value'. if (!(isset($child['#type']) && $child['#type'] == 'value')) { - $cell = array('data' => $child); + $cell = ['data' => $child]; if (isset($child['#cell_attributes'])) { $cell += $child['#cell_attributes']; } @@ -196,15 +201,24 @@ * * Callback for array_reduce() within * \Drupal\field_ui\Form\EntityDisplayFormBase::tablePreRender(). + * + * @param mixed $array + * Holds the return value of the previous iteration; in the case of the + * first iteration it instead holds the value of initial. + * @param mixed $a + * Holds the value of the current iteration. + * + * @return array + * Array where rendering order has been determined. */ public static function reduceOrder($array, $a) { - $array = !isset($array) ? array() : $array; + $array = !$array ? [] : $array; if ($a['name']) { $array[] = $a['name']; } if (!empty($a['children'])) { - uasort($a['children'], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); - $array = array_merge($array, array_reduce($a['children'], array('Drupal\field_ui\Element\FieldUiTable', 'reduceOrder'))); + uasort($a['children'], ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']); + $array = array_merge($array, array_reduce($a['children'], [static::class, 'reduceOrder'])); } return $array; diff -u b/core/modules/field_ui/templates/field-ui-table.html.twig b/core/modules/field_ui/templates/field-ui-table.html.twig --- b/core/modules/field_ui/templates/field-ui-table.html.twig +++ b/core/modules/field_ui/templates/field-ui-table.html.twig @@ -1,7 +1,7 @@ {# /** * @file - * Default theme implementation to display a field UI table. + * Default theme implementation to display a Field UI table. * * Available variables: * - attributes: HTML attributes to apply to the tag.