Unverified Commit cfd99349 authored by alexpott's avatar alexpott

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
...@@ -1502,6 +1502,7 @@ function template_preprocess_file_link(&$variables) { ...@@ -1502,6 +1502,7 @@ function template_preprocess_file_link(&$variables) {
// Set file classes to the options array. // Set file classes to the options array.
$variables['attributes'] = new Attribute($variables['attributes']); $variables['attributes'] = new Attribute($variables['attributes']);
$variables['attributes']->addClass($classes); $variables['attributes']->addClass($classes);
$variables['file_size'] = format_size($file->getSize());
$variables['link'] = \Drupal::l($link_text, Url::fromUri($url, $options)); $variables['link'] = \Drupal::l($link_text, Url::fromUri($url, $options));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Available variables: * Available variables:
* - attributes: The HTML attributes for the containing element. * - attributes: The HTML attributes for the containing element.
* - link: A link to the file. * - link: A link to the file.
* - file_size: The size of the file.
* *
* @see template_preprocess_file_link() * @see template_preprocess_file_link()
* *
...@@ -13,3 +14,7 @@ ...@@ -13,3 +14,7 @@
*/ */
#} #}
<span{{ attributes }}>{{ link }}</span> <span{{ attributes }}>{{ link }}</span>
{% if file_size %}
{# @todo remove class before Drupal 9.0.0 #}
<span class="file-size">({{ file_size }})</span>
{% endif %}
...@@ -21,11 +21,6 @@ function template_preprocess_image_widget(&$variables) { ...@@ -21,11 +21,6 @@ function template_preprocess_image_widget(&$variables) {
$variables['attributes'] = ['class' => ['image-widget', 'js-form-managed-file', 'form-managed-file', 'clearfix']]; $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'] = []; $variables['data'] = [];
foreach (Element::children($element) as $child) { foreach (Element::children($element) as $child) {
$variables['data'][$child] = $element[$child]; $variables['data'][$child] = $element[$child];
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
* - attributes: The HTML attributes for the containing element. * - attributes: The HTML attributes for the containing element.
* - link: A link to the file. * - link: A link to the file.
* - icon: The icon image representing the file type. * - icon: The icon image representing the file type.
* - file_size: The size of the file.
* *
* @see template_preprocess_file_link() * @see template_preprocess_file_link()
* @see stable_preprocess_image_widget()
*/ */
#} #}
{{ attach_library('classy/file') }} {{ attach_library('classy/file') }}
......
...@@ -23,3 +23,13 @@ function stable_preprocess_links(&$variables) { ...@@ -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> ';
}
}
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
* Available variables: * Available variables:
* - attributes: The HTML attributes for the containing element. * - attributes: The HTML attributes for the containing element.
* - link: A link to the file. * - link: A link to the file.
* - file_size: The size of the file.
* *
* @see template_preprocess_file_link() * @see template_preprocess_file_link()
* @see stable_preprocess_image_widget()
*/ */
#} #}
<span{{ attributes }}>{{ link }}</span> <span{{ attributes }}>{{ link }}</span>
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