You are here

image_module_test.module in Drupal 10

Provides Image module hook implementations for testing purposes.

File

core/modules/image/tests/modules/image_module_test/image_module_test.module
View source
<?php

/**
 * @file
 * Provides Image module hook implementations for testing purposes.
 */
use Drupal\image\ImageStyleInterface;
function image_module_test_file_download($uri) {
  $default_uri = \Drupal::state()
    ->get('image.test_file_download', FALSE);
  if ($default_uri == $uri) {
    return [
      'X-Image-Owned-By' => 'image_module_test',
    ];
  }
}

/**
 * Implements hook_image_effect_info_alter().
 */
function image_module_test_image_effect_info_alter(&$effects) {
  $state = \Drupal::state();

  // The 'image_module_test.counter' state variable value is set and accessed
  // from the ImageEffectsTest::testImageEffectsCaching() test and used to
  // signal if the image effect plugin definitions were computed or were
  // retrieved from the cache.
  // @see \Drupal\Tests\image\Kernel\ImageEffectsTest::testImageEffectsCaching()
  $counter = $state
    ->get('image_module_test.counter');

  // Increase the test counter, signaling that image effects were processed,
  // rather than being served from the cache.
  $state
    ->set('image_module_test.counter', ++$counter);
}

/**
 * Implements hook_image_style_presave().
 *
 * Used to save test third party settings in the image style entity.
 */
function image_module_test_image_style_presave(ImageStyleInterface $style) {
  $style
    ->setThirdPartySetting('image_module_test', 'foo', 'bar');
}