Issue #3033279 by lauriii, mandclu, Eli-T: Move markup from template_preprocess_image_widget to a template
parent
1094d0c8d1
commit
cfd993492f
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 %}
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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') }}
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
* 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()
|
||||
* @see stable_preprocess_image_widget()
|
||||
*/
|
||||
#}
|
||||
<span{{ attributes }}>{{ link }}</span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue