diff --git a/core/modules/image/image.admin.inc b/core/modules/image/image.admin.inc index df680651f55274d3ac49a69e3415f73e8dcb501e..46dcd5e430cb9c2693a94601e370f28aaa5f472e 100644 --- a/core/modules/image/image.admin.inc +++ b/core/modules/image/image.admin.inc @@ -748,15 +748,9 @@ function theme_image_style_preview($variables) { } /** - * Returns HTML for a 3x3 grid of checkboxes for image anchors. - * - * @param $variables - * An associative array containing: - * - element: A render element containing radio buttons. - * - * @ingroup themeable + * Preprocesses variables for image-anchor.html.twig. */ -function theme_image_anchor($variables) { +function template_preprocess_image_anchor(&$variables) { $element = $variables['element']; $rows = array(); @@ -770,8 +764,14 @@ function theme_image_anchor($variables) { $row = array(); } } - - return theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => array('image-anchor')))); + $variables['table'] = array( + '#theme' => 'table', + '#header' => array(), + '#rows' => $rows, + '#attributes' => array( + 'class' => array('image-anchor'), + ), + ); } /** @@ -809,16 +809,13 @@ function theme_image_scale_summary($variables) { } /** - * Returns HTML for a summary of an image crop effect. - * - * @param $variables - * An associative array containing: - * - data: The current configuration for this crop effect. - * - * @ingroup themeable + * Preprocesses variables for image-crop-summary.html.twig. */ -function theme_image_crop_summary($variables) { - return theme('image_resize_summary', $variables); +function template_preprocess_image_crop_summary(&$variables) { + $variables['summary'] = array( + '#theme' => 'image_resize_summary', + '#data' => $variables['data'], + ); } /** diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index ceb2c8ab9db776237b97a11d872d7fda1ff0f520..d7fbd32b3e85f287fdd2d9bee07bff6e0896a294 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -433,41 +433,50 @@ function theme_image_widget($variables) { } /** - * Returns HTML for an image field formatter. - * - * @param array $variables - * An associative array containing: - * - item: An array of image data. - * - image_style: An optional image style. - * - path: An optional array containing the link 'path' and link 'options'. - * - * @ingroup themeable + * Preprocesses variables for image-formatter.html.twig. */ -function theme_image_formatter($variables) { +function template_preprocess_image_formatter(&$variables) { $item = $variables['item']; + // Build a render array for the image from the formatter item. + $image = array(); + if(isset($item['uri'])) { + $image['#uri'] = $item['uri']; + } + if(isset($item['width'])) { + $image['#width'] = $item['width']; + } + if(isset($item['height'])) { + $image['#height'] = $item['height']; + } + if(isset($item['alt'])) { + $image['#alt'] = $item['alt']; + } // Do not output an empty 'title' attribute. - if (isset($item['title']) && drupal_strlen($item['title']) == 0) { - unset($item['title']); + if(isset($item['title']) && drupal_strlen($item['title']) != 0) { + $image['#title'] = $item['title']; + } + if(isset($item['attributes'])) { + $image['#attributes'] = $item['attributes']; } - if ($variables['image_style']) { - $item['style_name'] = $variables['image_style']; - $output = theme('image_style', $item); + // If this image needs an image style we need to handle it here. + if (!empty($variables['image_style'])) { + $image += array( + '#style_name' => $variables['image_style'], + '#theme' => 'image_style', + ); } else { - $output = theme('image', $item); + $image += array('#theme' => 'image'); } + $variables['image'] = $image; // The link path and link options are both optional, but for the options to be // processed, the link path must at least be an empty string. if (isset($variables['path']['path'])) { - $path = $variables['path']['path']; - $options = isset($variables['path']['options']) ? $variables['path']['options'] : array(); - // When displaying an image inside a link, the html option must be TRUE. - $options['html'] = TRUE; - $output = l($output, $path, $options); + $variables['path']['options'] = isset($variables['path']['options']) ? $variables['path']['options']: array(); + $variables['path']['options']['html'] = TRUE; + $variables['url'] = url($variables['path']['path'], $variables['path']['options']); } - - return $output; } diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 956eafd6992b6f968988a6a9ceea7928bfb99695..1ab20ce6e070f7bf802b5d67cc430303dc677550 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -221,6 +221,8 @@ function image_theme() { ), 'image_anchor' => array( 'render element' => 'element', + 'template' => 'image-anchor', + 'file' => 'image.admin.inc', ), 'image_resize_summary' => array( 'variables' => array('data' => NULL), @@ -230,6 +232,8 @@ function image_theme() { ), 'image_crop_summary' => array( 'variables' => array('data' => NULL), + 'template' => 'image-crop-summary', + 'file' => 'image.admin.inc', ), 'image_rotate_summary' => array( 'variables' => array('data' => NULL), @@ -240,7 +244,13 @@ function image_theme() { 'render element' => 'element', ), 'image_formatter' => array( - 'variables' => array('item' => NULL, 'path' => NULL, 'image_style' => NULL), + 'variables' => array( + 'item' => NULL, + 'path' => NULL, + 'image_style' => NULL + ), + 'template' => 'image-formatter', + 'file' => 'image.field.inc', ), ); } diff --git a/core/modules/image/templates/image-anchor.html.twig b/core/modules/image/templates/image-anchor.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..f97aabf14405f6059583356a18670c707c9c8205 --- /dev/null +++ b/core/modules/image/templates/image-anchor.html.twig @@ -0,0 +1,15 @@ +{# +/** + * @file + * Default theme implementation for a 3x3 grid of checkboxes for image anchors. + * + * Available variables: + * - table: HTML for the table of image anchors. + * + * @see template_preprocess() + * @see template_preprocess_image_anchor() + * + * @ingroup themeable + */ +#} +{{ table }} diff --git a/core/modules/image/templates/image-crop-summary.html.twig b/core/modules/image/templates/image-crop-summary.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..16fea6576f452c11354de04f33b9266f8a11f703 --- /dev/null +++ b/core/modules/image/templates/image-crop-summary.html.twig @@ -0,0 +1,15 @@ +{# +/** + * @file + * Default theme implementation for a summary of an image crop effect. + * + * Available variables: + * - summary: The current configuration for this crop effect. + * + * @see template_preprocess() + * @see template_preprocess_image_crop_summary() + * + * @ingroup themeable + */ +#} +{{ summary }} diff --git a/core/modules/image/templates/image-formatter.html.twig b/core/modules/image/templates/image-formatter.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..6d35048c20598ec3e9f43909ca30ca6c6fa8758e --- /dev/null +++ b/core/modules/image/templates/image-formatter.html.twig @@ -0,0 +1,26 @@ +{# +/** + * @file + * Default theme implementation to display a formatted image field. + * + * Available variables: + * - image: A collection of image data. + * - image_style: An optional image style. + * - path: An optional array containing the link 'path' and link 'options'. + * - url: An optional url string the image can be linked to. + * + * @TODO: Make twig able to find templates as per http://drupal.org/node/1777532 + * @todo: Revise template_preprocess_image_formatter to make this template + * more meaningful. + * + * @see template_preprocess() + * @see template_preprocess_image_formatter() + * + * @ingroup themeable + */ +#} +{% if url %} + {{ image }} +{% else %} + {{ image }} +{% endif %}