Commit 3f97e8ce authored by alexpott's avatar alexpott

Issue #2009580 by pplantinga, Samvel, hussainweb, andypost, siccababes:...

Issue #2009580 by pplantinga, Samvel, hussainweb, andypost, siccababes: Replace theme() with drupal_render() in image module.
parent 6fa0fe8a
...@@ -53,9 +53,14 @@ function theme_image_style_effects($variables) { ...@@ -53,9 +53,14 @@ function theme_image_style_effects($variables) {
))); )));
} }
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'image-style-effects'))); $table = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'image-style-effects'),
);
drupal_add_tabledrag('image-style-effects', 'order', 'sibling', 'image-effect-order-weight'); drupal_add_tabledrag('image-style-effects', 'order', 'sibling', 'image-effect-order-weight');
return $output; return drupal_render($table);
} }
/** /**
...@@ -117,10 +122,17 @@ function theme_image_style_preview($variables) { ...@@ -117,10 +122,17 @@ function theme_image_style_preview($variables) {
// Build the preview of the original image. // Build the preview of the original image.
$original_url = file_create_url($original_path); $original_url = file_create_url($original_path);
$image = array(
'#theme' => 'image',
'#uri' => $original_path,
'#alt' => t('Sample original image'),
'#title' => '',
'#attributes' => $original_image,
);
$output .= '<div class="preview-image-wrapper">'; $output .= '<div class="preview-image-wrapper">';
$output .= t('original') . ' (' . l(t('view actual size'), $original_url) . ')'; $output .= t('original') . ' (' . l(t('view actual size'), $original_url) . ')';
$output .= '<div class="preview-image original-image" style="' . $original_image['style'] . '">'; $output .= '<div class="preview-image original-image" style="' . $original_image['style'] . '">';
$output .= '<a href="' . $original_url . '">' . theme('image', array('uri' => $original_path, 'alt' => t('Sample original image'), 'title' => '', 'attributes' => $original_image)) . '</a>'; $output .= '<a href="' . $original_url . '">' . drupal_render($image) . '</a>';
$output .= '<div class="height" style="height: ' . $original_height . 'px"><span>' . $original_image['height'] . 'px</span></div>'; $output .= '<div class="height" style="height: ' . $original_height . 'px"><span>' . $original_image['height'] . 'px</span></div>';
$output .= '<div class="width" style="width: ' . $original_width . 'px"><span>' . $original_image['width'] . 'px</span></div>'; $output .= '<div class="width" style="width: ' . $original_width . 'px"><span>' . $original_image['width'] . 'px</span></div>';
$output .= '</div>'; // End preview-image. $output .= '</div>'; // End preview-image.
...@@ -128,10 +140,17 @@ function theme_image_style_preview($variables) { ...@@ -128,10 +140,17 @@ function theme_image_style_preview($variables) {
// Build the preview of the image style. // Build the preview of the image style.
$preview_url = file_create_url($preview_file) . '?cache_bypass=' . REQUEST_TIME; $preview_url = file_create_url($preview_file) . '?cache_bypass=' . REQUEST_TIME;
$image = array(
'#theme' => 'image',
'#uri' => $preview_url,
'#alt' => t('Sample modified image'),
'#title' => '',
'#attributes' => $preview_image,
);
$output .= '<div class="preview-image-wrapper">'; $output .= '<div class="preview-image-wrapper">';
$output .= check_plain($style->label()) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')'; $output .= check_plain($style->label()) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
$output .= '<div class="preview-image modified-image" style="' . $preview_image['style'] . '">'; $output .= '<div class="preview-image modified-image" style="' . $preview_image['style'] . '">';
$output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('uri' => $preview_url, 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_image)) . '</a>'; $output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . drupal_render($image) . '</a>';
$output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image['height'] . 'px</span></div>'; $output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image['height'] . 'px</span></div>';
$output .= '<div class="width" style="width: ' . $preview_width . 'px"><span>' . $preview_image['width'] . 'px</span></div>'; $output .= '<div class="width" style="width: ' . $preview_width . 'px"><span>' . $preview_image['width'] . 'px</span></div>';
$output .= '</div>'; // End preview-image. $output .= '</div>'; // End preview-image.
...@@ -166,7 +185,13 @@ function theme_image_anchor($variables) { ...@@ -166,7 +185,13 @@ function theme_image_anchor($variables) {
} }
} }
return theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => array('image-anchor')))); $table = array(
'#theme' => 'table',
'#header' => array(),
'#rows' => $rows,
'#attributes' => array('class' => array('image-anchor')),
);
return drupal_render($table);
} }
/** /**
...@@ -199,8 +224,11 @@ function theme_image_resize_summary($variables) { ...@@ -199,8 +224,11 @@ function theme_image_resize_summary($variables) {
* @ingroup themeable * @ingroup themeable
*/ */
function theme_image_scale_summary($variables) { function theme_image_scale_summary($variables) {
$data = $variables['data']; $image_resize_summary = array(
return theme('image_resize_summary', array('data' => $data)) . ' ' . ($data['upscale'] ? '(' . t('upscaling allowed') . ')' : ''); '#theme' => 'image_resize_summary',
'#data' => $variables['data'],
);
return drupal_render($image_resize_summary) . ' ' . ($variables['data']['upscale'] ? '(' . t('upscaling allowed') . ')' : '');
} }
/** /**
......
...@@ -311,7 +311,11 @@ function image_field_widget_process($element, &$form_state, $form) { ...@@ -311,7 +311,11 @@ function image_field_widget_process($element, &$form_state, $form) {
} }
$element['preview'] = array( $element['preview'] = array(
'#markup' => theme('image_style', $variables), '#theme' => 'image_style',
'#width' => $variables['width'],
'#height' => $variables['height'],
'#style_name' => $variables['style_name'],
'#uri' => $variables['uri'],
); );
// Store the dimensions in the form so the file doesn't have to be accessed // Store the dimensions in the form so the file doesn't have to be accessed
......
...@@ -84,14 +84,20 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface ...@@ -84,14 +84,20 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface
$elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state); $elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state);
$cardinality = $this->fieldDefinition->getFieldCardinality(); $cardinality = $this->fieldDefinition->getFieldCardinality();
$file_upload_help = array(
'#theme' => 'file_upload_help',
'#upload_validators' => $elements[0]['#upload_validators'],
'#cardinality' => $cardinality,
);
if ($cardinality == 1) { if ($cardinality == 1) {
// If there's only one field, return it as delta 0. // If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fids'])) { if (empty($elements[0]['#default_value']['fids'])) {
$elements[0]['#description'] = theme('file_upload_help', array('description' => $this->fieldDefinition->getFieldDescription(), 'upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); $file_upload_help['#description'] = $this->fieldDefinition->getFieldDescription();
$elements[0]['#description'] = drupal_render($file_upload_help);
} }
} }
else { else {
$elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators'], 'cardinality' => $cardinality)); $elements['#file_upload_description'] = drupal_render($file_upload_help);
} }
return $elements; return $elements;
......
...@@ -59,12 +59,13 @@ function _testImageFieldFormatters($scheme) { ...@@ -59,12 +59,13 @@ function _testImageFieldFormatters($scheme) {
// Test that the default formatter is being used. // Test that the default formatter is being used.
$image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(); $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri();
$image_info = array( $image = array(
'uri' => $image_uri, '#theme' => 'image',
'width' => 40, '#uri' => $image_uri,
'height' => 20, '#width' => 40,
'#height' => 20,
); );
$default_output = theme('image', $image_info); $default_output = drupal_render($image);
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.'); $this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Test the image linked to file formatter. // Test the image linked to file formatter.
...@@ -76,7 +77,13 @@ function _testImageFieldFormatters($scheme) { ...@@ -76,7 +77,13 @@ function _testImageFieldFormatters($scheme) {
$display->setComponent($field_name, $display_options) $display->setComponent($field_name, $display_options)
->save(); ->save();
$default_output = l(theme('image', $image_info), file_create_url($image_uri), array('html' => TRUE)); $image = array(
'#theme' => 'image',
'#uri' => $image_uri,
'#width' => 40,
'#height' => 20,
);
$default_output = l($image, file_create_url($image_uri), array('html' => TRUE));
$this->drupalGet('node/' . $nid); $this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, 'Image linked to file formatter displaying correctly on full node view.'); $this->assertRaw($default_output, 'Image linked to file formatter displaying correctly on full node view.');
// Verify that the image can be downloaded. // Verify that the image can be downloaded.
...@@ -100,7 +107,13 @@ function _testImageFieldFormatters($scheme) { ...@@ -100,7 +107,13 @@ function _testImageFieldFormatters($scheme) {
$display_options['settings']['image_link'] = 'content'; $display_options['settings']['image_link'] = 'content';
$display->setComponent($field_name, $display_options) $display->setComponent($field_name, $display_options)
->save(); ->save();
$default_output = l(theme('image', $image_info), 'node/' . $nid, array('html' => TRUE, 'attributes' => array('class' => 'active'))); $image = array(
'#theme' => 'image',
'#uri' => $image_uri,
'#width' => 40,
'#height' => 20,
);
$default_output = l($image, 'node/' . $nid, array('html' => TRUE, 'attributes' => array('class' => 'active')));
$this->drupalGet('node/' . $nid); $this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, 'Image linked to content formatter displaying correctly on full node view.'); $this->assertRaw($default_output, 'Image linked to content formatter displaying correctly on full node view.');
...@@ -113,11 +126,14 @@ function _testImageFieldFormatters($scheme) { ...@@ -113,11 +126,14 @@ function _testImageFieldFormatters($scheme) {
// Ensure the derivative image is generated so we do not have to deal with // Ensure the derivative image is generated so we do not have to deal with
// image style callback paths. // image style callback paths.
$this->drupalGet(entity_load('image_style', 'thumbnail')->buildUrl($image_uri)); $this->drupalGet(entity_load('image_style', 'thumbnail')->buildUrl($image_uri));
$image_info['uri'] = $image_uri; $image_style = array(
$image_info['width'] = 100; '#theme' => 'image_style',
$image_info['height'] = 50; '#uri' => $image_uri,
$image_info['style_name'] = 'thumbnail'; '#width' => 100,
$default_output = theme('image_style', $image_info); '#height' => 50,
'#style_name' => 'thumbnail',
);
$default_output = drupal_render($image_style);
$this->drupalGet('node/' . $nid); $this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, 'Image style thumbnail formatter displaying correctly on full node view.'); $this->assertRaw($default_output, 'Image style thumbnail formatter displaying correctly on full node view.');
...@@ -164,29 +180,31 @@ function testImageFieldSettings() { ...@@ -164,29 +180,31 @@ function testImageFieldSettings() {
// Verify that the attached image is being previewed using the 'medium' // Verify that the attached image is being previewed using the 'medium'
// style. // style.
$node = node_load($nid, TRUE); $node = node_load($nid, TRUE);
$image_info = array( $image_style = array(
'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), '#theme' => 'image_style',
'width' => 220, '#uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(),
'height' => 110, '#width' => 220,
'style_name' => 'medium', '#height' => 110,
'#style_name' => 'medium',
); );
$default_output = theme('image_style', $image_info); $default_output = drupal_render($image_style);
$this->assertRaw($default_output, "Preview image is displayed using 'medium' style."); $this->assertRaw($default_output, "Preview image is displayed using 'medium' style.");
// Add alt/title fields to the image and verify that they are displayed. // Add alt/title fields to the image and verify that they are displayed.
$image_info = array( $image = array(
'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), '#theme' => 'image',
'alt' => $this->randomName(), '#uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(),
'title' => $this->randomName(), '#alt' => $this->randomName(),
'width' => 40, '#title' => $this->randomName(),
'height' => 20, '#width' => 40,
'#height' => 20,
); );
$edit = array( $edit = array(
$field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][alt]' => $image_info['alt'], $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][alt]' => $image['#alt'],
$field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][title]' => $image_info['title'], $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][title]' => $image['#title'],
); );
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published'));
$default_output = theme('image', $image_info); $default_output = drupal_render($image);
$this->assertRaw($default_output, 'Image displayed using user supplied alt and title attributes.'); $this->assertRaw($default_output, 'Image displayed using user supplied alt and title attributes.');
// Verify that alt/title longer than allowed results in a validation error. // Verify that alt/title longer than allowed results in a validation error.
...@@ -232,9 +250,13 @@ function testImageFieldDefaultImage() { ...@@ -232,9 +250,13 @@ function testImageFieldDefaultImage() {
// Clear field info cache so the new default image is detected. // Clear field info cache so the new default image is detected.
field_info_cache_clear(); field_info_cache_clear();
$field = field_info_field($field_name); $field = field_info_field($field_name);
$image = file_load($field['settings']['default_image']); $file = file_load($field['settings']['default_image']);
$this->assertTrue($image->isPermanent(), 'The default image status is permanent.'); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.');
$default_output = theme('image', array('uri' => $image->getFileUri())); $image = array(
'#theme' => 'image',
'#uri' => $file->getFileUri(),
);
$default_output = drupal_render($image);
$this->drupalGet('node/' . $node->id()); $this->drupalGet('node/' . $node->id());
$this->assertRaw($default_output, 'Default image displayed when no user supplied image is present.'); $this->assertRaw($default_output, 'Default image displayed when no user supplied image is present.');
...@@ -242,12 +264,13 @@ function testImageFieldDefaultImage() { ...@@ -242,12 +264,13 @@ function testImageFieldDefaultImage() {
// is not displayed. // is not displayed.
$nid = $this->uploadNodeImage($images[1], $field_name, 'article'); $nid = $this->uploadNodeImage($images[1], $field_name, 'article');
$node = node_load($nid, TRUE); $node = node_load($nid, TRUE);
$image_info = array( $image = array(
'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), '#theme' => 'image',
'width' => 40, '#uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(),
'height' => 20, '#width' => 40,
'#height' => 20,
); );
$image_output = theme('image', $image_info); $image_output = drupal_render($image);
$this->drupalGet('node/' . $nid); $this->drupalGet('node/' . $nid);
$this->assertNoRaw($default_output, 'Default image is not displayed when user supplied image is present.'); $this->assertNoRaw($default_output, 'Default image is not displayed when user supplied image is present.');
$this->assertRaw($image_output, 'User supplied image is displayed.'); $this->assertRaw($image_output, 'User supplied image is displayed.');
...@@ -274,13 +297,17 @@ function testImageFieldDefaultImage() { ...@@ -274,13 +297,17 @@ function testImageFieldDefaultImage() {
field_info_cache_clear(); field_info_cache_clear();
$private_field = field_info_field($private_field_name); $private_field = field_info_field($private_field_name);
$image = file_load($private_field['settings']['default_image']); $file = file_load($private_field['settings']['default_image']);
$this->assertEqual('private', file_uri_scheme($image->getFileUri()), 'Default image uses private:// scheme.'); $this->assertEqual('private', file_uri_scheme($file->getFileUri()), 'Default image uses private:// scheme.');
$this->assertTrue($image->isPermanent(), 'The default image status is permanent.'); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.');
// Create a new node with no image attached and ensure that default private // Create a new node with no image attached and ensure that default private
// image is displayed. // image is displayed.
$node = $this->drupalCreateNode(array('type' => 'article')); $node = $this->drupalCreateNode(array('type' => 'article'));
$default_output = theme('image', array('uri' => $image->getFileUri())); $image = array(
'#theme' => 'image',
'#uri' => $file->getFileUri(),
);
$default_output = drupal_render($image);
$this->drupalGet('node/' . $node->id()); $this->drupalGet('node/' . $node->id());
$this->assertRaw($default_output, 'Default private image displayed when no user supplied image is present.'); $this->assertRaw($default_output, 'Default private image displayed when no user supplied image is present.');
} }
......
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