diff --git a/core/modules/image/image.services.yml b/core/modules/image/image.services.yml index 90ff836794..bbddf3ee8b 100644 --- a/core/modules/image/image.services.yml +++ b/core/modules/image/image.services.yml @@ -4,9 +4,11 @@ services: arguments: ['@stream_wrapper_manager'] tags: - { name: path_processor_inbound, priority: 300 } - plugin.manager.image_derivative: - class: Drupal\image\Plugin\ImageDerivativePluginManager + image.processor: + class: Drupal\image\ImageProcessor parent: default_plugin_manager + tags: + - { name: plugin_manager_cache_clear } plugin.manager.image.effect: class: Drupal\image\ImageEffectManager parent: default_plugin_manager diff --git a/core/modules/image/src/Annotation/ImageDerivative.php b/core/modules/image/src/Annotation/ImageProcessPipeline.php similarity index 60% rename from core/modules/image/src/Annotation/ImageDerivative.php rename to core/modules/image/src/Annotation/ImageProcessPipeline.php index 633ef6268b..26ad974e44 100644 --- a/core/modules/image/src/Annotation/ImageDerivative.php +++ b/core/modules/image/src/Annotation/ImageProcessPipeline.php @@ -5,11 +5,11 @@ use Drupal\Component\Annotation\Plugin; /** - * Defines a Plugin annotation object for ImageDerivative plugins. + * Defines a Plugin annotation object for ImageProcessPipeline plugins. * * @Annotation */ -class ImageDerivative extends Plugin { +class ImageProcessPipeline extends Plugin { /** * The plugin ID. @@ -27,6 +27,13 @@ class ImageDerivative extends Plugin { * * @ingroup plugin_translatable */ - public $help; + public $description; + + /** + * The name of the derived image handler class. + * + * @var string + */ + public $derivedImageClass; } diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 4209fbc188..c22f581572 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -165,7 +165,7 @@ protected static function replaceImageStyle(ImageStyleInterface $style) { */ public function buildUri($uri) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); return $derivative_handler ->setImageStyle($this) ->setSourceUri($uri) @@ -177,7 +177,7 @@ public function buildUri($uri) { */ public function buildUrl($path, $clean_urls = NULL) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); return $derivative_handler ->setImageStyle($this) ->setSourceUri($path) @@ -189,7 +189,7 @@ public function buildUrl($path, $clean_urls = NULL) { */ public function flush($path = NULL) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); $derivative_handler->setImageStyle($this); if (isset($path)) { // A specific image path has been provided. Flush only that derivative. @@ -207,7 +207,7 @@ public function flush($path = NULL) { */ public function createDerivative($original_uri, $derivative_uri) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); $derivative_handler ->setImageStyle($this) ->setSourceUri($original_uri); @@ -222,7 +222,7 @@ public function createDerivative($original_uri, $derivative_uri) { */ public function transformDimensions(array &$dimensions, $uri) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); $dimensions = $derivative_handler ->setImageStyle($this) ->setSourceUri($uri) @@ -236,7 +236,7 @@ public function transformDimensions(array &$dimensions, $uri) { */ public function getDerivativeExtension($extension) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); return $derivative_handler ->setImageStyle($this) ->getDerivativeImageFileExtension($extension); @@ -247,7 +247,7 @@ public function getDerivativeExtension($extension) { */ public function getPathToken($uri) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); return $derivative_handler ->setImageStyle($this) ->getPathToken($uri); @@ -267,7 +267,7 @@ public function deleteImageEffect(ImageEffectInterface $effect) { */ public function supportsUri($uri) { @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 9.x.x and will be removed in y.y.y.', E_USER_DEPRECATED); - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); return $derivative_handler ->setImageStyle($this) ->setSourceUri($uri) diff --git a/core/modules/image/src/Plugin/ImageDerivativePluginManager.php b/core/modules/image/src/ImageProcessor.php similarity index 44% rename from core/modules/image/src/Plugin/ImageDerivativePluginManager.php rename to core/modules/image/src/ImageProcessor.php index f33e4fdf8b..5b39895b65 100644 --- a/core/modules/image/src/Plugin/ImageDerivativePluginManager.php +++ b/core/modules/image/src/ImageProcessor.php @@ -1,30 +1,31 @@ alterInfo('image_derivative_plugin_info'); - $this->setCacheBackend($cache_backend, 'image_derivative_plugins'); + $this->alterInfo('image_process_pipeline_plugin_info'); + $this->setCacheBackend($cache_backend, 'image_process_pipeline_plugins'); } } diff --git a/core/modules/image/src/Plugin/ImageDerivative/Core.php b/core/modules/image/src/Plugin/ImageProcessPipeline/Core.php similarity index 97% rename from core/modules/image/src/Plugin/ImageDerivative/Core.php rename to core/modules/image/src/Plugin/ImageProcessPipeline/Core.php index 8cb305008a..f67324da00 100644 --- a/core/modules/image/src/Plugin/ImageDerivative/Core.php +++ b/core/modules/image/src/Plugin/ImageProcessPipeline/Core.php @@ -1,6 +1,6 @@ drupalGetTestFiles('image'))); // Create derivative image. - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); $styles = ImageStyle::loadMultiple(); $style = reset($styles); $original_uri = $file->getFileUri(); @@ -78,7 +78,7 @@ public function testBuildDerivativeFromImageObject() { $this->assertNull($image->getFileSize()); // Create derivative. - $derivative_handler = \Drupal::service('plugin.manager.image_derivative')->createInstance('core'); + $derivative_handler = \Drupal::service('image.processor')->createInstance('core'); $style = ImageStyle::load('medium'); $desired_filepath = 'public://' . $this->randomMachineName(); $derivative_uri = $desired_filepath . '/test_0.png'; diff --git a/core/modules/image/tests/src/Unit/CoreImageDerivativePluginTest.php b/core/modules/image/tests/src/Unit/CoreImageProcessPipelinePluginTest.php similarity index 91% rename from core/modules/image/tests/src/Unit/CoreImageDerivativePluginTest.php rename to core/modules/image/tests/src/Unit/CoreImageProcessPipelinePluginTest.php index a5934a5d25..b956283749 100644 --- a/core/modules/image/tests/src/Unit/CoreImageDerivativePluginTest.php +++ b/core/modules/image/tests/src/Unit/CoreImageProcessPipelinePluginTest.php @@ -7,16 +7,16 @@ use Drupal\image\ImageEffectManager; /** - * @coversDefaultClass \Drupal\image\Plugin\ImageDerivative\Core + * @coversDefaultClass \Drupal\image\Plugin\ImageProcessPipeline\Core * * @group Image */ -class CoreImageDerivativePluginTest extends UnitTestCase { +class CoreImageProcessPipelinePluginTest extends UnitTestCase { /** * Gets a mocked image style for testing. * - * @param \Drupal\image\ImageEffectInterface|\PHPUnit_Framework_MockObject_MockObject $image_effect + * @param \Drupal\image\ImageEffectInterface|\PHPUnit\Framework\MockObject\MockObject $image_effect * The image effect used for testing. * * @return \Drupal\image\ImageStyleInterface @@ -54,12 +54,12 @@ protected function getImageStyleMock($image_effect, $stubs = []) { } /** - * Gets a mocked Core ImageDerivativePlugin for testing. + * Gets a mocked Core ImageProcessPipelinePlugin for testing. * * @return \Drupal\image\ImageStyleInterface * The mocked image style. */ - protected function getCoreImageDerivativePluginMock($stubs = []) { + protected function getCoreImageProcessPipelinePluginMock($stubs = []) { $image_factory = $this->getMockBuilder('\Drupal\Core\Image\ImageFactory') ->disableOriginalConstructor() ->getMock(); @@ -80,7 +80,7 @@ protected function getCoreImageDerivativePluginMock($stubs = []) { 'fileUriTarget', 'fileDefaultScheme', ]; - $derivative_handler = $this->getMockBuilder('\Drupal\image\Plugin\ImageDerivative\Core') + $derivative_handler = $this->getMockBuilder('\Drupal\image\Plugin\ImageProcessPipeline\Core') ->setConstructorArgs([ [], 'core', @@ -126,7 +126,7 @@ public function testBuildDerivativeUri() { ->will($this->returnValue('png')); $image_style = $this->getImageStyleMock($image_effect); - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler->setImageStyle($image_style)->setSourceUri('public://test.jpeg'); $this->assertEquals('public://styles/testImageStyleEntityId/public/test.jpeg.png', $derivative_handler->buildDerivativeUri()); @@ -140,7 +140,7 @@ public function testBuildDerivativeUri() { ->will($this->returnArgument(0)); $image_style = $this->getImageStyleMock($image_effect); - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler->setImageStyle($image_style)->setSourceUri('public://test.jpeg'); $this->assertEquals('public://styles/testImageStyleEntityId/public/test.jpeg', $derivative_handler->buildDerivativeUri()); } @@ -161,7 +161,7 @@ public function testGetDerivativeImageFileExtension() { // The mock ImageEffect::getDerivativeExtension method is always returning // 'png'. - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler->setImageStyle($image_style); $extensions = ['jpeg', 'gif', 'png']; foreach ($extensions as $extension) { @@ -184,7 +184,7 @@ public function testGetDerivativeImageDimensions() { // The mock ImageEffect::transformDimensions method is halving each // dimension. - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler ->setImageStyle($image_style) ->setSourceUri('noUri') @@ -198,7 +198,7 @@ public function testGetDerivativeImageDimensions() { public function testIsSourceImageFileDerivable() { // The mock ImageFactory::getSupportedExtensions() method is returning // ['gif', 'png']. - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler->setSourceUri('bingo.png'); $this->assertTrue($derivative_handler->isSourceImageFileDerivable()); $derivative_handler->setSourceUri('bingo.svg'); @@ -220,7 +220,7 @@ public function testGetPathToken() { $image_style = $this->getImageStyleMock($image_effect); // Assert the extension has been added to the URI before creating the token. - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler->setImageStyle($image_style); $this->assertSame($derivative_handler->getPathToken('public://test.jpeg.png'), $derivative_handler->getPathToken('public://test.jpeg')); $this->assertSame('rD82Rz5j', $derivative_handler->getPathToken('public://test.jpeg')); @@ -236,7 +236,7 @@ public function testGetPathToken() { $image_style = $this->getImageStyleMock($image_effect); // Assert no extension has been added to the URI before creating the token. - $derivative_handler = $this->getCoreImageDerivativePluginMock(); + $derivative_handler = $this->getCoreImageProcessPipelinePluginMock(); $derivative_handler->setImageStyle($image_style); $this->assertNotEquals($derivative_handler->getPathToken('public://test.jpeg.png'), $derivative_handler->getPathToken('public://test.jpeg')); $this->assertSame('sbDHSih4', $derivative_handler->getPathToken('public://test.jpeg'));