1<?php 2 3/** 4 * @file 5 * Functions to support theming in the Stable theme. 6 */ 7 8use Drupal\Component\Utility\Html; 9 10/** 11 * Implements hook_library_info_alter(). 12 */ 13function stable_library_info_alter(&$libraries, $extension) { 14 // Add removed css/filter.admin.css file back so that themes overriding 15 // this file continue getting same behavior until Drupal 9. 16 if ($extension === 'filter') { 17 if (isset($libraries['drupal.filter.admin'])) { 18 $libraries['drupal.filter.admin']['css']['theme']['css/filter.admin.css'] = []; 19 } 20 if (isset($libraries['drupal.filter'])) { 21 $libraries['drupal.filter']['css']['theme']['css/filter.admin.css'] = []; 22 } 23 } 24} 25 26/** 27 * Implements template_preprocess_links(). 28 */ 29function stable_preprocess_links(&$variables) { 30 // @deprecated in Drupal 8.0.x and will be removed before 9.0.0. This feature 31 // of adding a class based on the associative key can cause CSS class name 32 // conflicts. 33 if (!empty($variables['links'])) { 34 foreach ($variables['links'] as $key => $value) { 35 if (!is_numeric($key)) { 36 $class = Html::getClass($key); 37 $variables['links'][$key]['attributes']->addClass($class); 38 } 39 } 40 } 41} 42 43/** 44 * Implements hook_element_info_alter(). 45 */ 46function stable_element_info_alter(array &$info) { 47 if (array_key_exists('text_format', $info)) { 48 $info['text_format']['#process'][] = 'stable_process_text_format'; 49 } 50} 51 52/** 53 * #process callback, for adding classes to filter components. 54 * 55 * @param array $element 56 * Render array for the text_format element. 57 * 58 * @return array 59 * Text_format element with the filter classes added. 60 */ 61function stable_process_text_format(array $element) { 62 $element['format']['#attributes']['class'][] = 'filter-wrapper'; 63 $element['format']['guidelines']['#attributes']['class'][] = 'filter-guidelines'; 64 $element['format']['format']['#attributes']['class'][] = 'filter-list'; 65 $element['format']['help']['#attributes']['class'][] = 'filter-help'; 66 67 return $element; 68} 69 70/** 71 * Implements hook_preprocess_image_widget(). 72 */ 73function stable_preprocess_image_widget(&$variables) { 74 if (!empty($variables['element']['fids']['#value'])) { 75 $file = reset($variables['element']['#files']); 76 $variables['data']['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> '; 77 } 78} 79