Skip to content
Snippets Groups Projects
Commit d95dc67e authored by catch's avatar catch
Browse files

Issue #3127116 by phthlaap, AjitS, cmlara, AmbyH, smustgrave, alexpott,...

Issue #3127116 by phthlaap, AjitS, cmlara, AmbyH, smustgrave, alexpott, quietone: Image styles - thumbnails are broken in config page when private file system is used

(cherry picked from commit fcc1ba65)
parent 555c098f
No related branches found
No related tags found
26 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #104300 passed
Pipeline: drupal

#104319

    Pipeline: drupal

    #104316

      Pipeline: drupal

      #104310

        +1
        ......@@ -58,6 +58,11 @@ function template_preprocess_image_style_preview(&$variables) {
        $style->createDerivative($original_path, $preview_file);
        }
        $preview_image = $image_factory->get($preview_file);
        // Generate an itok.
        $defaultScheme = \Drupal::config('system.file')->get('default_scheme');
        $variables['itok'] = $style->getPathToken($defaultScheme . '://' . $original_path);
        $variables['derivative'] = [
        'url' => $file_url_generator->generateString($preview_file),
        'width' => $preview_image->getWidth(),
        ......@@ -89,7 +94,7 @@ function template_preprocess_image_style_preview(&$variables) {
        // to prevent caching of images on the client side.
        $variables['derivative']['rendered'] = [
        '#theme' => 'image',
        '#uri' => $variables['derivative']['url'] . '?cache_bypass=' . $variables['cache_bypass'],
        '#uri' => $variables['derivative']['url'] . '?cache_bypass=' . $variables['cache_bypass'] . '&itok=' . $variables['itok'],
        '#alt' => t('Sample modified image'),
        '#title' => '',
        '#attributes' => [
        ......
        ......@@ -167,6 +167,20 @@ function image_file_download($uri) {
        }
        return -1;
        }
        // If it is the sample image we need to grant access.
        $samplePath = \Drupal::config('image.settings')->get('preview_image');
        if ($path === $samplePath) {
        $image = \Drupal::service('image.factory')->get($samplePath);
        return [
        // Send headers describing the image's size, and MIME-type.
        'Content-Type' => $image->getMimeType(),
        'Content-Length' => $image->getFileSize(),
        // By not explicitly setting them here, this uses normal Drupal
        // Expires, Cache-Control and ETag headers to prevent proxy or
        // browser caching of private images.
        ];
        }
        }
        /**
        ......
        ......@@ -112,6 +112,7 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st
        $target = $request->query->get('file');
        $image_uri = $scheme . '://' . $target;
        $image_uri = $this->streamWrapperManager->normalizeUri($image_uri);
        $sample_image_uri = $scheme . '://' . $this->config('image.settings')->get('preview_image');
        if ($this->streamWrapperManager->isValidScheme($scheme)) {
        $normalized_target = $this->streamWrapperManager->getTarget($image_uri);
        ......@@ -181,6 +182,11 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st
        }
        }
        // If it is default sample.png, ignore scheme.
        if ($image_uri === $sample_image_uri) {
        $image_uri = $target;
        }
        // Don't try to generate file if source is missing.
        if (!$this->sourceImageExists($image_uri, $token_is_valid)) {
        // If the image style converted the extension, it has been added to the
        ......
        ......@@ -518,4 +518,38 @@ public function testImageStyleAccess() {
        $this->assertSession()->pageTextContains("Select a new effect");
        }
        /**
        * Tests the display of preview images using a private scheme.
        */
        public function testPreviewImageShowInPrivateScheme(): void {
        $this->config('system.file')->set('default_scheme', 'private')->save();
        /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
        $file_url_generator = \Drupal::service('file_url_generator');
        // Get the original preview image file in core config.
        $original_path = $this->config('image.settings')->get('preview_image');
        $style = ImageStyle::create(['name' => 'test_foo', 'label' => 'test foo']);
        $style->save();
        // Build the derivative preview image file with the Image Style.
        // @see template_preprocess_image_style_preview()
        $preview_file = $style->buildUri($original_path);
        $style->createDerivative($original_path, $preview_file);
        // Check if the derivative image exists.
        $this->assertFileExists($preview_file);
        // Generate itok token for the preview image.
        $itok = $style->getPathToken('private://' . $original_path);
        $url = $file_url_generator->generateAbsoluteString($preview_file);
        $url .= '?itok=' . $itok;
        // Check if the preview image with style is shown.
        $this->drupalGet($url);
        $this->assertSession()->statusCodeEquals(200);
        $this->assertSession()->responseHeaderContains('Content-Type', 'image/png');
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment