public static FieldUiTable::preRenderRegionRows($elements)
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\Element
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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 ; } |
Please login to continue.