diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 782ae70..bd6a4c5 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -63,7 +63,7 @@ function template_preprocess_file_widget_multiple(&$variables) { // preview or failed validation). $widgets = array(); foreach (Element::children($element) as $key) { - $widgets[] = &$element[$key]; + $widgets[$key] = &$element[$key]; } usort($widgets, '_field_multiple_value_form_sort_helper'); @@ -81,57 +81,44 @@ function template_preprocess_file_widget_multiple(&$variables) { $operations_elements = array(); foreach (Element::children($widget) as $sub_key) { if (isset($widget[$sub_key]['#type']) && $widget[$sub_key]['#type'] == 'submit') { + $operations_elements[] = $widget[$sub_key]; hide($widget[$sub_key]); - $operations_elements[] = &$widget[$sub_key]; } } // Delay rendering of the "Display" option and the weight selector, so that // each can be rendered later in its own column. if ($element['#display_field']) { + $display_element = $widget['display']; hide($widget['display']); } + + $weight_element = $widget['_weight']; + $weight_element['#attributes']['class'] = [$weight_class]; hide($widget['_weight']); - // Render everything else together in a column, without the normal wrappers. + // Store the remaining elements in a column, without the normal wrappers. $widget['#theme_wrappers'] = array(); - $information = drupal_render($widget); - - // Render the previously hidden elements, using render() instead of - // drupal_render(), to undo the earlier hide(). - $operations = ''; - foreach ($operations_elements as $operation_element) { - $operations .= render($operation_element); - } - $display = ''; - if ($element['#display_field']) { - unset($widget['display']['#title']); - $display = array( - 'data' => render($widget['display']), - 'class' => array('checkbox'), - ); - } - $widget['_weight']['#attributes']['class'] = array($weight_class); - $weight = render($widget['_weight']); + $information = $widget; + hide($widget); // Arrange the row with all of the rendered columns. $row = array(); - $row[] = $information; - if ($element['#display_field']) { - $row[] = $display; + $row['information'] = $information; + if (!empty($display_element)) { + unset($display_element['#title']); + $display_element['#wrapper_attributes']['class'] = ['checkbox']; + $row['display'] = $display_element; } - $row[] = $weight; - $row[] = SafeMarkup::set($operations); - $rows[] = array( - 'data' => $row, - 'class' => isset($widget['#attributes']['class']) ? array_merge($widget['#attributes']['class'], array('draggable')) : array('draggable'), - ); + $row['weight'] = $weight_element; + $row['operations'] = $operations_elements; + $row['#attributes']['class'] = isset($information['#attributes']['class']) ? array_merge($information['#attributes']['class'], ['draggable']) : ['draggable']; + $rows[$key] = $row; } $variables['table'] = array( '#type' => 'table', '#header' => $headers, - '#rows' => $rows, '#attributes' => array( 'id' => $table_id, ), @@ -142,7 +129,7 @@ function template_preprocess_file_widget_multiple(&$variables) { 'group' => $weight_class, ), ), - ); + ) + $rows; $variables['element'] = $element; }