Commit bc65847d authored by alexpott's avatar alexpott
Browse files

Issue #2009014 by c4rl, hussainweb, Samvel, jenlampton, benjifisher: Replace...

Issue #2009014 by c4rl, hussainweb, Samvel, jenlampton, benjifisher: Replace theme() with drupal_render() in file module.
parent 637beb94
...@@ -596,7 +596,7 @@ function theme_file_widget($variables) { ...@@ -596,7 +596,7 @@ function theme_file_widget($variables) {
if (!empty($element['fids']['#value'])) { if (!empty($element['fids']['#value'])) {
// Add the file size after the file name. // Add the file size after the file name.
$file = reset($element['#files']); $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 .= drupal_render_children($element);
$output .= '</div>'; $output .= '</div>';
...@@ -645,7 +645,7 @@ function theme_file_widget_multiple($variables) { ...@@ -645,7 +645,7 @@ function theme_file_widget_multiple($variables) {
// Save the uploading row for last. // Save the uploading row for last.
if (empty($widget['#files'])) { if (empty($widget['#files'])) {
$widget['#title'] = $element['#file_upload_title']; $widget['#title'] = $element['#file_upload_title'];
$widget['#description'] = $element['#file_upload_description']; $widget['#description'] = drupal_render($element['#file_upload_description']);
continue; continue;
} }
...@@ -703,8 +703,16 @@ function theme_file_widget_multiple($variables) { ...@@ -703,8 +703,16 @@ function theme_file_widget_multiple($variables) {
drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class); drupal_add_tabledrag($table_id, 'order', 'sibling', $weight_class);
$output = ''; $build = array(
$output = empty($rows) ? '' : theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id))); '#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#attributes' => array(
'id' => $table_id,
),
);
$output = empty($rows) ? '' : drupal_render($build);
$output .= drupal_render_children($element); $output .= drupal_render_children($element);
return $output; return $output;
} }
...@@ -804,11 +812,22 @@ function theme_file_formatter_table($variables) { ...@@ -804,11 +812,22 @@ function theme_file_formatter_table($variables) {
foreach ($variables['items'] as $delta => $item) { foreach ($variables['items'] as $delta => $item) {
if ($item['display'] && $item['entity']) { if ($item['display'] && $item['entity']) {
$rows[] = array( $rows[] = array(
theme('file_link', array('file' => $item['entity'])), array(
'data' => array(
'#theme' => 'file_link',
'#file' => $item['entity'],
),
),
format_size($item['entity']->getSize()), 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);
} }
...@@ -978,7 +978,8 @@ function file_ajax_upload() { ...@@ -978,7 +978,8 @@ function file_ajax_upload() {
// Invalid request. // 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'); 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(); $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(); list($form, $form_state) = ajax_get_form();
...@@ -987,7 +988,8 @@ function file_ajax_upload() { ...@@ -987,7 +988,8 @@ function file_ajax_upload() {
// Invalid form_build_id. // 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'); 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(); $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. // Get the current element and count the number of files.
...@@ -1014,7 +1016,8 @@ function file_ajax_upload() { ...@@ -1014,7 +1016,8 @@ function file_ajax_upload() {
$form['#suffix'] .= '<span class="ajax-new-content"></span>'; $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); $output = drupal_render($form);
$js = drupal_add_js(); $js = drupal_add_js();
$settings = drupal_merge_js_settings($js['settings']['data']); $settings = drupal_merge_js_settings($js['settings']['data']);
...@@ -1321,17 +1324,18 @@ function file_managed_file_process($element, &$form_state, $form) { ...@@ -1321,17 +1324,18 @@ function file_managed_file_process($element, &$form_state, $form) {
if (!empty($fids) && $element['#files']) { if (!empty($fids) && $element['#files']) {
foreach ($element['#files'] as $delta => $file) { foreach ($element['#files'] as $delta => $file) {
$file_link = array(
'#theme' => 'file_link',
'#file' => $file,
);
if ($element['#multiple']) { if ($element['#multiple']) {
$element['file_' . $delta]['selected'] = array( $element['file_' . $delta]['selected'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => theme('file_link', array('file' => $file)) . ' ', '#title' => drupal_render($file_link),
); );
} }
else { else {
$element['file_' . $delta]['filename'] = array( $element['file_' . $delta]['filename'] = $file_link += array('#weight' => -10);
'#markup' => theme('file_link', array('file' => $file)) . ' ',
'#weight' => -10,
);
} }
} }
} }
...@@ -1655,11 +1659,6 @@ function file_managed_file_pre_render($element) { ...@@ -1655,11 +1659,6 @@ function file_managed_file_pre_render($element) {
*/ */
function theme_file_link($variables) { function theme_file_link($variables) {
$file = $variables['file']; $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 // Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples // http://microformats.org/wiki/file-format-examples
...@@ -1678,7 +1677,13 @@ function theme_file_link($variables) { ...@@ -1678,7 +1677,13 @@ function theme_file_link($variables) {
$options['attributes']['title'] = check_plain($file->getFilename()); $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>';
} }
/** /**
......
...@@ -164,7 +164,12 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface ...@@ -164,7 +164,12 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface
// field. These are added here so that they may be referenced easily // field. These are added here so that they may be referenced easily
// through a hook_form_alter(). // through a hook_form_alter().
$elements['#file_upload_title'] = t('Add a new file'); $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; return $elements;
...@@ -225,7 +230,13 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang ...@@ -225,7 +230,13 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang
$default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value']; $default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value'];
if (empty($default_fids)) { 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; $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE;
if ($cardinality != 1 && $cardinality != -1) { if ($cardinality != 1 && $cardinality != -1) {
$element['#element_validate'] = array('file_field_widget_multiple_count_validate'); $element['#element_validate'] = array('file_field_widget_multiple_count_validate');
......
...@@ -36,8 +36,11 @@ public function buildOptionsForm(&$form, &$form_state) { ...@@ -36,8 +36,11 @@ public function buildOptionsForm(&$form, &$form_state) {
public function render($values) { public function render($values) {
$data = $values->{$this->field_alias}; $data = $values->{$this->field_alias};
if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') { if (!empty($this->options['filemime_image']) && $data !== NULL && $data !== '') {
$fake_file = (object) array('filemime' => $data); $file_icon = array(
$data = theme('file_icon', array('file' => $fake_file)); '#theme' => 'file_icon',
'#file' => $values->_entity,
);
$data = drupal_render($file_icon);
} }
return $this->render_link($data, $values); return $this->render_link($data, $values);
......
...@@ -61,7 +61,11 @@ function testNodeDisplay() { ...@@ -61,7 +61,11 @@ function testNodeDisplay() {
// Check that the default formatter is displaying with the file name. // Check that the default formatter is displaying with the file name.
$node = node_load($nid, TRUE); $node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $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.'); $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. // Turn the "display" option off and check that the file is no longer displayed.
......
...@@ -404,7 +404,7 @@ function theme_image_widget($variables) { ...@@ -404,7 +404,7 @@ function theme_image_widget($variables) {
$output .= '<div class="image-widget-data">'; $output .= '<div class="image-widget-data">';
if (!empty($element['fids']['#value'])) { if (!empty($element['fids']['#value'])) {
$file = reset($element['#files']); $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 .= drupal_render_children($element);
$output .= '</div>'; $output .= '</div>';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment