picture_everywhere-1.0.0/picture_everywhere.module

picture_everywhere.module
<?php

/**
 * @file
 * Picture Everywhere module.
 */

/**
 * Implements hook_theme_registry_alter().
 */
function picture_everywhere_theme_registry_alter(array &$theme_registry): void {
  $config = \Drupal::config('picture_everywhere.settings');

  $enabled_themes = $config->get('themes');
  if (!$enabled_themes) {
    return;
  }

  $active_theme = \Drupal::theme()->getActiveTheme()->getName();
  if (!in_array($active_theme, $enabled_themes, TRUE)) {
    return;
  }

  $module_path = \Drupal::service('extension.list.module')
    ->getPath('picture_everywhere');
  $module_template_path = $module_path . '/templates';

  if (isset($theme_registry['image'])) {
    $image = &$theme_registry['image'];
    $image['type'] = 'module';
    $image['theme path'] = $module_path;
    $image['path'] = $module_template_path;
    $image['preprocess functions'][] = [
      'Drupal\picture_everywhere\Preprocess',
      'preprocessImage',
    ];

    // Register an additional variable that can be passed to the image #theme to
    // communicate that it is already being rendered inside of a <picture> tag.
    if (!isset($image['variables']['in_picture'])) {
      $image['variables']['in_picture'] = NULL;
    }
  }

  if (isset($theme_registry['responsive_image'])) {
    $resp_image = &$theme_registry['responsive_image'];
    $resp_image['type'] = 'module';
    $resp_image['theme path'] = $module_path;
    $resp_image['path'] = $module_template_path;
    $resp_image['preprocess functions'][] = [
      'Drupal\picture_everywhere\Preprocess',
      'preprocessResponsiveImage',
    ];
  }

  // Integration with the svg_image_field module.
  if (isset($theme_registry['svg_image_field_formatter'])) {
    $svg_image_field = &$theme_registry['svg_image_field_formatter'];
    $svg_image_field['type'] = 'module';
    $svg_image_field['theme path'] = $module_path;
    $svg_image_field['path'] = $module_template_path;
    $svg_image_field['preprocess functions'][] = [
      'Drupal\picture_everywhere\Preprocess',
      'preprocessSvgImageFieldFormatter',
    ];
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc