Verified Commit 996fb537 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2833129 by Lendude, firewaller, idebr, psebborn, ravi.shankar, Berdir,...

Issue #2833129 by Lendude, firewaller, idebr, psebborn, ravi.shankar, Berdir, catch: hook_image_style_flush doesn't get the $path passed to Drupal\image\Entity\ImageStyle::flush() method
parent ae55070f
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -32,8 +32,11 @@ function hook_image_effect_info_alter(&$effects) {
 *
 * @param \Drupal\image\ImageStyleInterface $style
 *   The image style object that is being flushed.
 * @param string|null $path
 *   (optional) The original image path or URI. If it's supplied, only this
 *   image derivative will be flushed.
 */
function hook_image_style_flush($style) {
function hook_image_style_flush($style, $path = NULL) {
  // Empty cached data that contains information about the style.
  \Drupal::cache('mymodule')->deleteAll();
}
+12 −12
Original line number Diff line number Diff line
@@ -278,9 +278,8 @@ public function flush($path = NULL) {
          // Ignore failed deletes.
        }
      }
      return $this;
    }

    else {
      // Delete the style directory in each registered wrapper.
      $wrappers = $this->getStreamWrapperManager()->getWrappers(StreamWrapperInterface::WRITE_VISIBLE);
      foreach ($wrappers as $wrapper => $wrapper_data) {
@@ -293,10 +292,11 @@ public function flush($path = NULL) {
          }
        }
      }
    }

    // Let other modules update as necessary on flush.
    $module_handler = \Drupal::moduleHandler();
    $module_handler->invokeAll('image_style_flush', [$this]);
    $module_handler->invokeAll('image_style_flush', [$this, $path]);

    // Clear caches so that formatters may be added for this style.
    \Drupal::service('theme.registry')->reset();
+8 −0
Original line number Diff line number Diff line
@@ -38,3 +38,11 @@ function image_module_test_image_effect_info_alter(&$effects) {
function image_module_test_image_style_presave(ImageStyleInterface $style) {
  $style->setThirdPartySetting('image_module_test', 'foo', 'bar');
}

/**
 * Implements hook_image_style_flush().
 */
function image_module_test_image_style_flush($style, $path = NULL) {
  $state = \Drupal::state();
  $state->set('image_module_test_image_style_flush.called', $path);
}
+7 −0
Original line number Diff line number Diff line
@@ -125,6 +125,13 @@ public function testFlush() {

    // Post flush, expected no image in the 'private' wrapper.
    $this->assertEquals(0, $this->getImageCount($style, 'private'), new FormattableMarkup('Image style %style flushed correctly for %wrapper wrapper.', ['%style' => $style->label(), '%wrapper' => 'private']));

    $state = \Drupal::state();
    $state->set('image_module_test_image_style_flush.called', FALSE);
    $style->flush();
    $this->assertNull($state->get('image_module_test_image_style_flush.called'));
    $style->flush('/made/up/path');
    $this->assertSame('/made/up/path', $state->get('image_module_test_image_style_flush.called'));
  }

}