Unverified Commit cfd99349 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3033279 by lauriii, mandclu, Eli-T: Move markup from...

Issue #3033279 by lauriii, mandclu, Eli-T: Move markup from template_preprocess_image_widget to a template
parent 1094d0c8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1502,6 +1502,7 @@ function template_preprocess_file_link(&$variables) {
  // Set file classes to the options array.
  $variables['attributes'] = new Attribute($variables['attributes']);
  $variables['attributes']->addClass($classes);
  $variables['file_size'] = format_size($file->getSize());

  $variables['link'] = \Drupal::l($link_text, Url::fromUri($url, $options));
}
+5 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 * Available variables:
 * - attributes: The HTML attributes for the containing element.
 * - link: A link to the file.
 * - file_size: The size of the file.
 *
 * @see template_preprocess_file_link()
 *
@@ -13,3 +14,7 @@
 */
#}
<span{{ attributes }}>{{ link }}</span>
{% if file_size %}
  {# @todo remove class before Drupal 9.0.0 #}
  <span class="file-size">({{ file_size }})</span>
{% endif %}
+0 −5
Original line number Diff line number Diff line
@@ -21,11 +21,6 @@ function template_preprocess_image_widget(&$variables) {

  $variables['attributes'] = ['class' => ['image-widget', 'js-form-managed-file', 'form-managed-file', 'clearfix']];

  if (!empty($element['fids']['#value'])) {
    $file = reset($element['#files']);
    $element['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
  }

  $variables['data'] = [];
  foreach (Element::children($element) as $child) {
    $variables['data'][$child] = $element[$child];
+2 −0
Original line number Diff line number Diff line
@@ -7,8 +7,10 @@
 * - attributes: The HTML attributes for the containing element.
 * - link: A link to the file.
 * - icon: The icon image representing the file type.
 * - file_size: The size of the file.
 *
 * @see template_preprocess_file_link()
 * @see stable_preprocess_image_widget()
 */
#}
{{ attach_library('classy/file') }}
+10 −0
Original line number Diff line number Diff line
@@ -23,3 +23,13 @@ function stable_preprocess_links(&$variables) {
    }
  }
}

/**
 * Implements hook_preprocess_image_widget().
 */
function stable_preprocess_image_widget(&$variables) {
  if (!empty($variables['element']['fids']['#value'])) {
    $file = reset($variables['element']['#files']);
    $variables['data']['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
  }
}
Loading