You are here

starterkit_theme.theme in Drupal 9

Functions to support theming.

File

core/themes/starterkit_theme/starterkit_theme.theme
View source
<?php

/**
 * @file
 * Functions to support theming.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Form\ViewsForm;

/**
 * Implements hook_preprocess_links__media_library_menu().
 *
 * This targets the menu of available media types in the media library's modal
 * dialog.
 *
 * @todo Do this in the relevant template once
 *   https://www.drupal.org/project/drupal/issues/3088856 is resolved.
 */
function starterkit_theme_preprocess_links__media_library_menu(array &$variables) {
  foreach ($variables['links'] as &$link) {
    $link['link']['#options']['attributes']['class'][] = 'media-library-menu__link';
  }
}

/**
 * Implements hook_form_alter().
 */
function starterkit_theme_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $form_object = $form_state
    ->getFormObject();
  if ($form_object instanceof ViewsForm && strpos($form_object
    ->getBaseFormId(), 'views_form_media_library') === 0) {
    $form['#attributes']['class'][] = 'media-library-views-form';
  }
}

/**
 * Implements hook_preprocess_image_widget().
 */
function starterkit_theme_preprocess_image_widget(array &$variables) {
  $data =& $variables['data'];

  // This prevents image widget templates from rendering preview container HTML
  // to users that do not have permission to access these previews.
  // @todo revisit in https://drupal.org/node/953034
  // @todo revisit in https://drupal.org/node/3114318
  if (isset($data['preview']['#access']) && $data['preview']['#access'] === FALSE) {
    unset($data['preview']);
  }
}

Functions

Namesort descending Description
starterkit_theme_form_alter Implements hook_form_alter().
starterkit_theme_preprocess_image_widget Implements hook_preprocess_image_widget().
starterkit_theme_preprocess_links__media_library_menu Implements hook_preprocess_links__media_library_menu().