You are here

function template_preprocess_minisite_widget in Mini site 8

Prepares variables for minisite widget templates.

Default template: minisite-widget.html.twig.

Parameters

array $variables: An associative array containing:

  • element: A render element representing the minisite field widget.

File

./minisite.theme.inc, line 43
minisite.theme.inc

Code

function template_preprocess_minisite_widget(array &$variables) {
  $element = $variables['element'];
  $variables['attributes'] = [
    'class' => [
      'minisite-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];
  }
}