summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-07-26 05:44:30 (GMT)
committerAlex Pott2013-07-26 05:44:30 (GMT)
commitbc65847d68e6b604144c628d8fe027716ffdb918 (patch)
tree288ee917cf3bd2a4be6de84197d37cba4764a6b7
parent637beb94d0716d58e7627dc176196898f930156e (diff)
Issue #2009014 by c4rl, hussainweb, Samvel, jenlampton, benjifisher: Replace theme() with drupal_render() in file module.
-rw-r--r--core/modules/file/file.field.inc31
-rw-r--r--core/modules/file/file.module33
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php15
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/views/field/FileMime.php7
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php6
-rw-r--r--core/modules/image/image.field.inc2
6 files changed, 68 insertions, 26 deletions
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index 3305a00..7e693c7 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -596,7 +596,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'] .= ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
+ $element['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';
@@ -645,7 +645,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;
}
@@ -703,8 +703,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;
}
@@ -804,11 +812,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 8db8612..ded5b13 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -978,7 +978,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();
@@ -987,7 +988,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.
@@ -1014,7 +1016,8 @@ function file_ajax_upload() {
$form['#suffix'] .= '<span class="ajax-new-content"></span>';
}
- $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']);
@@ -1321,17 +1324,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(
- '#markup' => theme('file_link', array('file' => $file)) . ' ',
- '#weight' => -10,
- );
+ $element['file_' . $delta]['filename'] = $file_link += array('#weight' => -10);
}
}
}
@@ -1655,11 +1659,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
@@ -1678,7 +1677,13 @@ function theme_file_link($variables) {
$options['attributes']['title'] = check_plain($file->getFilename());
}
- return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
+ $file_icon = array(
+ '#theme' => 'file_icon',
+ '#file' => $file,
+ '#icon_directory' => $variables['icon_directory'],
+ );
+
+ return '<span class="file">' . drupal_render($file_icon) . ' ' . l($link_text, file_create_url($file->getFileUri()), $options) . '</span>';
}
/**
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 a32e217..245ec34 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
@@ -164,7 +164,12 @@ class FileWidget extends WidgetBase {
// 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;
@@ -225,7 +230,13 @@ class FileWidget extends WidgetBase {
$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 5b69e10..8fa60d5 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 @@ class FileMime extends File {
public 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 87e099e..4ef654d 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 @@ class FileFieldDisplayTest extends FileFieldTestBase {
// 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]['target_id']);
- $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, 'Default formatter displaying correctly on full node view.');
// Turn the "display" option off and check that the file is no longer displayed.
diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc
index 824f14c..1f0e87b 100644
--- a/core/modules/image/image.field.inc
+++ b/core/modules/image/image.field.inc
@@ -404,7 +404,7 @@ function theme_image_widget($variables) {
$output .= '<div class="image-widget-data">';
if (!empty($element['fids']['#value'])) {
$file = reset($element['#files']);
- $element['file_' . $file->id()]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
+ $element['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';