function ImageModuleTestHooks::fileDownload

Same name and namespace in other branches
  1. 11.x core/modules/image/tests/modules/image_module_test/src/Hook/ImageModuleTestHooks.php \Drupal\image_module_test\Hook\ImageModuleTestHooks::fileDownload()

Implements hook_file_download().

Attributes

#[Hook('file_download')]

File

core/modules/image/tests/modules/image_module_test/src/Hook/ImageModuleTestHooks.php, line 54

Class

ImageModuleTestHooks
Hook implementations for image_module_test.

Namespace

Drupal\image_module_test\Hook

Code

public function fileDownload($uri) : array|int {
  $default_uri = \Drupal::keyValue('image')->get('test_file_download', FALSE);
  if ($default_uri == $uri) {
    return [
      'X-Image-Owned-By' => 'image_module_test',
    ];
  }
  // When we have custom stream wrapper is enabled, do the validation based
  // on state variable to allow it.
  if (str_starts_with($uri, 'image-test-dummy://')) {
    if (\Drupal::state()->get('image_module_test.allow_image_test_dummy', FALSE)) {
      return [
        'X-Allowed-By' => 'image_module_test',
      ];
    }
    return -1;
  }
  return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.