stable.theme 1006 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php

/**
 * @file
 * Functions to support theming in the Stable theme.
 */

use Drupal\Component\Utility\Html;

/**
 * Implements template_preprocess_links().
 */
function stable_preprocess_links(&$variables) {
  // @deprecated in Drupal 8.0.x and will be removed before 9.0.0. This feature
  // of adding a class based on the associative key can cause CSS class name
  // conflicts.
  if (!empty($variables['links'])) {
    foreach ($variables['links'] as $key => $value) {
      if (!is_numeric($key)) {
        $class = Html::getClass($key);
        $variables['links'][$key]['attributes']->addClass($class);
      }
    }
  }
}
26 27 28 29 30 31 32 33 34 35

/**
 * 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> ';
  }
}