classy.theme 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support theming in the Classy theme.
  5. */
  6. use Drupal\Core\Form\FormStateInterface;
  7. use Drupal\views\Form\ViewsForm;
  8. /**
  9. * Implements hook_preprocess_links__media_library_menu().
  10. *
  11. * This targets the menu of available media types in the media library's modal
  12. * dialog.
  13. *
  14. * @todo Do this in the relevant template once
  15. * https://www.drupal.org/project/drupal/issues/3088856 is resolved.
  16. */
  17. function classy_preprocess_links__media_library_menu(array &$variables) {
  18. foreach ($variables['links'] as &$link) {
  19. $link['link']['#options']['attributes']['class'][] = 'media-library-menu__link';
  20. }
  21. }
  22. /**
  23. * Implements hook_form_alter().
  24. */
  25. function classy_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  26. $form_object = $form_state->getFormObject();
  27. if ($form_object instanceof ViewsForm && strpos($form_object->getBaseFormId(), 'views_form_media_library') === 0) {
  28. $form['#attributes']['class'][] = 'media-library-views-form';
  29. }
  30. }
  31. /**
  32. * Implements hook_preprocess_image_widget().
  33. */
  34. function classy_preprocess_image_widget(array &$variables) {
  35. $data = &$variables['data'];
  36. if (isset($data['preview']['#access']) && $data['preview']['#access'] === FALSE) {
  37. unset($data['preview']);
  38. }
  39. }