public static function FieldUiTable::preRenderRegionRows in Drupal 9
Same name and namespace in other branches
- 8 core/modules/field_ui/src/Element/FieldUiTable.php \Drupal\field_ui\Element\FieldUiTable::preRenderRegionRows()
- 10 core/modules/field_ui/src/Element/FieldUiTable.php \Drupal\field_ui\Element\FieldUiTable::preRenderRegionRows()
Performs pre-render to move #regions to rows.
Parameters
array $elements: A structured array containing two sub-levels of elements. Properties used:
- #tabledrag: The value is a list of $options arrays that are passed to drupal_attach_tabledrag(). The HTML ID of the table is added to each $options array.
Return value
array The $element with prepared variables ready for field-ui-table.html.twig.
File
- core/
modules/ field_ui/ src/ Element/ FieldUiTable.php, line 139
Class
- FieldUiTable
- Provides a field_ui table element.
Namespace
Drupal\field_ui\ElementCode
public static function preRenderRegionRows($elements) {
// Determine the colspan to use for region rows, by checking the number of
// columns in the headers.
$columns_count = 0;
foreach ($elements['#header'] as $header) {
$columns_count += is_array($header) && isset($header['colspan']) ? $header['colspan'] : 1;
}
$rows = [];
foreach (Element::children($elements) as $key) {
$rows[$key] = $elements[$key];
unset($elements[$key]);
}
// 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'])) {
$elements['#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';
$elements['#rows'][] = [
'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) {
$element = $rows[$name];
$row = [
'data' => [],
];
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 = [
'data' => $child,
];
if (isset($child['#cell_attributes'])) {
$cell += $child['#cell_attributes'];
}
$row['data'][] = $cell;
}
}
$elements['#rows'][] = $row;
}
}
return $elements;
}