diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index a46696c..3907957 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -643,7 +643,7 @@ function theme_file_widget($variables) { if (!empty($element['fids']['#value'])) { // Add the file size after the file name. $file = reset($element['#files']); - $element['file_' . $file->id()]['filename']['#markup'] .= ' (' . format_size($file->getSize()) . ') '; + $element['file_' . $file->id()]['filename']['#suffix'] = ' (' . format_size($file->getSize()) . ') '; } $output .= drupal_render_children($element); $output .= ''; @@ -692,7 +692,7 @@ function theme_file_widget_multiple($variables) { // Save the uploading row for last. if (empty($widget['#files'])) { $widget['#title'] = $element['#file_upload_title']; - $widget['#description'] = $element['#file_upload_description']; + $widget['#description'] = drupal_render($element['#file_upload_description']); continue; } @@ -750,8 +750,16 @@ function theme_file_widget_multiple($variables) { drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class); - $output = ''; - $output = empty($rows) ? '' : theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id))); + $build = array( + '#theme' => 'table', + '#header' => $headers, + '#rows' => $rows, + '#attributes' => array( + 'id' => $table_id, + ), + ); + + $output = empty($rows) ? '' : drupal_render($build); $output .= drupal_render_children($element); return $output; } @@ -851,11 +859,22 @@ function theme_file_formatter_table($variables) { foreach ($variables['items'] as $delta => $item) { if ($item['display'] && $item['entity']) { $rows[] = array( - theme('file_link', array('file' => $item['entity'])), + array( + 'data' => array( + '#theme' => 'file_link', + '#file' => $item['entity'], + ), + ), format_size($item['entity']->getSize()), ); } } - return empty($rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows)); + $build = array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + ); + + return empty($rows) ? '' : drupal_render($build); } diff --git a/core/modules/file/file.module b/core/modules/file/file.module index f7a7c86..c765b41 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -741,7 +741,8 @@ function file_ajax_upload() { // Invalid request. drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error'); $response = new AjaxResponse(); - return $response->addCommand(new ReplaceCommand(NULL, theme('status_messages'))); + $status_messages = array('#theme' => 'status_messages'); + return $response->addCommand(new ReplaceCommand(NULL, drupal_render($status_messages))); } list($form, $form_state) = ajax_get_form(); @@ -750,7 +751,8 @@ function file_ajax_upload() { // Invalid form_build_id. drupal_set_message(t('An unrecoverable error occurred. Use of this form has expired. Try reloading the page and submitting again.'), 'error'); $response = new AjaxResponse(); - return $response->addCommand(new ReplaceCommand(NULL, theme('status_messages'))); + $status_messages = array('#theme' => 'status_messages'); + return $response->addCommand(new ReplaceCommand(NULL, drupal_render($status_messages))); } // Get the current element and count the number of files. @@ -777,7 +779,8 @@ function file_ajax_upload() { $form['#suffix'] .= ''; } - $form['#prefix'] .= theme('status_messages'); + $status_messages = array('#theme' => 'status_messages'); + $form['#prefix'] .= drupal_render($status_messages); $output = drupal_render($form); $js = drupal_add_js(); $settings = drupal_merge_js_settings($js['settings']['data']); @@ -957,18 +960,18 @@ function file_managed_file_process($element, &$form_state, $form) { if (!empty($fids) && $element['#files']) { foreach ($element['#files'] as $delta => $file) { + $file_link = array( + '#theme' => 'file_link', + '#file' => $file, + ); if ($element['#multiple']) { $element['file_' . $delta]['selected'] = array( '#type' => 'checkbox', - '#title' => theme('file_link', array('file' => $file)) . ' ', + '#title' => drupal_render($file_link), ); } else { - $element['file_' . $delta]['filename'] = array( - '#type' => 'markup', - '#markup' => theme('file_link', array('file' => $file)) . ' ', - '#weight' => -10, - ); + $element['file_' . $delta]['filename'] = $file_link += array('#weight' => -10); } } } @@ -1292,11 +1295,6 @@ function file_managed_file_pre_render($element) { */ function theme_file_link($variables) { $file = $variables['file']; - $icon_directory = $variables['icon_directory']; - - $url = file_create_url($file->getFileUri()); - // theme_file_icon() requires a file entity, make sure it gets one. - $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory)); // Set options as per anchor format described at // http://microformats.org/wiki/file-format-examples @@ -1315,7 +1313,13 @@ function theme_file_link($variables) { $options['attributes']['title'] = check_plain($file->getFilename()); } - return '' . $icon . ' ' . l($link_text, $url, $options) . ''; + $file_icon = array( + '#theme' => 'file_icon', + '#file' => $file, + '#icon_directory' => $variables['icon_directory'], + ); + + return '' . drupal_render($file_icon) . ' ' . l($link_text, file_create_url($file->getFileUri()), $options) . ''; } /** diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 4603288..fd705d6 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -155,7 +155,12 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ // field. These are added here so that they may be referenced easily // through a hook_form_alter(). $elements['#file_upload_title'] = t('Add a new file'); - $elements['#file_upload_description'] = theme('file_upload_help', array('description' => '', 'upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); + $elements['#file_upload_description'] = array( + '#theme' => 'file_upload_help', + '#description' => '', + '#upload_validators' => $elements[0]['#upload_validators'], + '#cardinality' => $cardinality, + ); } return $elements; @@ -216,7 +221,13 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value']; if (empty($default_fids)) { - $element['#description'] = theme('file_upload_help', array('description' => $element['#description'], 'upload_validators' => $element['#upload_validators'], 'cardinality' => $cardinality)); + $file_upload_help = array( + '#theme' => 'file_upload_help', + '#description' => $element['#description'], + '#upload_validators' => $element['#upload_validators'], + '#cardinality' => $cardinality, + ); + $element['#description'] = drupal_render($file_upload_help); $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE; if ($cardinality != 1 && $cardinality != -1) { $element['#element_validate'] = array('file_field_widget_multiple_count_validate'); diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php b/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php index a63c2d6..0693bde 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php @@ -36,8 +36,11 @@ public function buildOptionsForm(&$form, &$form_state) { function render($values) { $data = $values->{$this->field_alias}; if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') { - $fake_file = (object) array('filemime' => $data); - $data = theme('file_icon', array('file' => $fake_file)); + $file_icon = array( + '#theme' => 'file_icon', + '#file' => $values->_entity, + ); + $data = drupal_render($file_icon); } return $this->render_link($data, $values); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index ebce0b1..dead424 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -61,7 +61,11 @@ function testNodeDisplay() { // Check that the default formatter is displaying with the file name. $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); - $default_output = theme('file_link', array('file' => $node_file)); + $file_link = array( + '#theme' => 'file_link', + '#file' => $node_file, + ); + $default_output = drupal_render($file_link); $this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.')); // Turn the "display" option off and check that the file is no longer displayed.