stable.theme 2.3 KB

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