diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 14f3276..e526cb3 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -5,7 +5,6 @@ * Allows administrators to attach custom fields to fieldable types. */ -use Drupal\Component\Utility\Html; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; @@ -49,18 +48,6 @@ function field_ui_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_theme(). - */ -function field_ui_theme() { - return array( - 'field_ui_table' => array( - 'render element' => 'elements', - 'function' => 'theme_field_ui_table', - ), - ); -} - -/** * Implements hook_entity_type_build(). */ function field_ui_entity_type_build(array &$entity_types) { @@ -189,87 +176,6 @@ function field_ui_view_mode_delete(EntityViewModeInterface $view_mode) { } /** - * Returns HTML for Field UI overview tables. - * - * @param $variables - * An associative array containing: - * - elements: An associative array containing a Form API structure to be - * rendered as a table. - * - * @ingroup themeable - */ -function theme_field_ui_table($variables) { - $elements = $variables['elements']; - $table = array('#type' => 'table'); - - // Add table headers and attributes. - foreach (array('#header', '#attributes') as $key) { - if (isset($elements[$key])) { - $table[$key] = $elements[$key]; - } - } - - // Determine the colspan to use for region rows, by checking the number of - // columns in the headers. - $columns_count = 0; - foreach ($table['#header'] as $header) { - $columns_count += (is_array($header) && isset($header['colspan']) ? $header['colspan'] : 1); - } - - // Render rows, region by region. - foreach ($elements['#regions'] as $region_name => $region) { - $region_name_class = Html::getClass($region_name); - - // Add region rows. - if (isset($region['title']) && empty($region['invisible'])) { - $table['#rows'][] = array( - 'class' => array('region-title', 'region-' . $region_name_class . '-title'), - 'no_striping' => TRUE, - 'data' => array( - array('data' => $region['title'], 'colspan' => $columns_count), - ), - ); - } - if (isset($region['message'])) { - $class = (empty($region['rows_order']) ? 'region-empty' : 'region-populated'); - $table['#rows'][] = array( - 'class' => array('region-message', 'region-' . $region_name_class . '-message', $class), - 'no_striping' => TRUE, - 'data' => array( - array('data' => $region['message'], 'colspan' => $columns_count), - ), - ); - } - - // Add form rows, in the order determined at pre-render time. - foreach ($region['rows_order'] as $name) { - $element = $elements[$name]; - - $row = array('data' => array()); - if (isset($element['#attributes'])) { - $row += $element['#attributes']; - } - - // Render children as table cells. - foreach (Element::children($element) as $cell_key) { - $child = &$element[$cell_key]; - // Do not render a cell for children of #type 'value'. - if (!(isset($child['#type']) && $child['#type'] == 'value')) { - $cell = array('data' => drupal_render($child)); - if (isset($child['#cell_attributes'])) { - $cell += $child['#cell_attributes']; - } - $row['data'][] = $cell; - } - } - $table['#rows'][] = $row; - } - } - - return drupal_render($table); -} - -/** * Implements hook_local_tasks_alter(). */ function field_ui_local_tasks_alter(&$local_tasks) { diff --git a/core/modules/field_ui/src/Element/FieldUiTable.php b/core/modules/field_ui/src/Element/FieldUiTable.php index 361a17e..092e6f9 100644 --- a/core/modules/field_ui/src/Element/FieldUiTable.php +++ b/core/modules/field_ui/src/Element/FieldUiTable.php @@ -7,23 +7,89 @@ namespace Drupal\field_ui\Element; -use Drupal\Core\Render\Element\RenderElement; +use Drupal\Component\Utility\Html; +use Drupal\Core\Render\Element\Table; /** * Provides a field_ui table element. * * @RenderElement("field_ui_table") */ -class FieldUiTable extends RenderElement { +class FieldUiTable extends Table { /** * {@inheritdoc} */ public function getInfo() { + $info = parent::getInfo(); + $class = get_class($this); + $parent_class = get_parent_class($this); return array( - '#theme' => 'field_ui_table', - '#regions' => array('' => array()), - ); + '#regions' => ['' => []], + // Render properties. + '#pre_render' => [ + [$parent_class, 'preRenderTable'], + [$class, 'preRenderTable'], + ], + ) + $info; + } + + /** + * {@inheritdoc} + */ + public static function preRenderTable($element) { + // Determine the colspan to use for region rows, by checking the number of + // columns in the headers. + $columns_count = 0; + foreach ($element['#header'] as $header) { + $columns_count += (is_array($header) && isset($header['colspan']) ? $header['colspan'] : 1); + } + + // Render rows, region by region. + foreach ($element['#regions'] as $region_name => $region) { + $region_name_class = Html::getClass($region_name); + + // Add region rows. + if (isset($region['title']) && empty($region['invisible'])) { + $element['#rows'][] = [ + 'class' => ['region-title', 'region-' . $region_name_class . '-title'], + 'no_striping' => TRUE, + 'data' => [['data' => $region['title'], 'colspan' => $columns_count]], + ]; + } + if (isset($region['message'])) { + $class = (empty($region['rows_order']) ? 'region-empty' : 'region-populated'); + $element['#rows'][] = array( + 'class' => ['region-message', 'region-' . $region_name_class . '-message', $class], + 'no_striping' => TRUE, + 'data' => [['data' => $region['message'], 'colspan' => $columns_count]], + ); + } + + // Add form rows, in the order determined at pre-render time. + foreach ($region['rows_order'] as $name) { + $region_element = $element[$name]; + + $row = ['data' => []]; + if (isset($region_element['#attributes'])) { + $row += $region_element['#attributes']; + } + + // Render children as table cells. + foreach (Element::children($region_element) as $cell_key) { + $child = &$element[$cell_key]; + // Do not render a cell for children of #type 'value'. + if (!(isset($child['#type']) && $child['#type'] == 'value')) { + $cell = ['data' => drupal_render($child)]; + if (isset($child['#cell_attributes'])) { + $cell += $child['#cell_attributes']; + } + $row['data'][] = $cell; + } + } + $element['#rows'][] = $row; + } + } } }