Commit 1c5ea715 authored by Malcolm Young's avatar Malcolm Young
Browse files

Issue #3280567 by malcomio: Display human-readable name of image style

parent b0544ae0
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -57,13 +57,13 @@ function imagestyles_preprocess_media(&$variables) {
  foreach ($styles as $style_name => $style) {
    if ($style_name != 'original') {
      $style_open = !empty($config[$style_name]);
      $header_items[] = imagestyles_header_item($style_name);
      $header_items[] = imagestyles_header_item($style_name, $style->get('label'));
      $variables['content']['imagestyles'][$style_name] = imagestyles_render_image_style($image_uri, $style, $style_open);
    }
  }

  // Add the original image to our render array.
  $header_items[] = imagestyles_header_item('original');
  $header_items[] = imagestyles_header_item('original', 'Original image');
  $style_id = imagestyles_style_id('original');
  $original_open = !empty($config['original']);
  $dimensions = $source->getMetadata($media_entity, 'width') . 'x' . $source->getMetadata($media_entity, 'height');
@@ -159,6 +159,8 @@ function imagestyles_get_file_entity($media_entity) {
 */
function imagestyles_render_image_style($image_uri, $style, $open) {
  $style_name = $style->getName();
  $style_label = $style->get('label');

  $style_id = imagestyles_style_id($style_name);

  $effects = $style->getEffects();
@@ -177,7 +179,7 @@ function imagestyles_render_image_style($image_uri, $style, $open) {
    ];
  }

  return imagestyles_render_array($image_uri, $style_id, $style_name, $open,
  return imagestyles_render_array($image_uri, $style_id, $style_label, $open,
    $effect_labels, $style_name);
}

@@ -266,8 +268,8 @@ function imagestyles_style_id($style_name) {
 * @return \Drupal\Core\Link
 *   A link to the preview anchor.
 */
function imagestyles_header_item($style_name) {
function imagestyles_header_item($style_name, $style_label) {
  $style_id = imagestyles_style_id($style_name);
  $anchor = Url::fromUserInput('#' . $style_id);
  return Link::fromTextAndUrl($style_name, $anchor);
  return Link::fromTextAndUrl($style_label, $anchor);
}