<?php

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_preprocess_image_widget().
 */
function holy_theme_preprocess_image_widget(array &$variables): void {
  $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']);
  }
}

/**
 * Implements hook_preprocess_page().
 */
function holy_preprocess_page(array &$variables) {

  // Is canvas variable in page.html.twig 
  $canvas_routes = [
    'entity.canvas_page.canonical',
    'canvas.api.layout.get',
    'canvas.api.layout.post',
    'canvas.api.layout.patch',
  ];
  $variables['is_canvas_page'] = in_array(\Drupal::routeMatch()->getRouteName(), $canvas_routes, TRUE);

}
