diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 5811c0e..1acccdf 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -347,7 +347,7 @@ public function getEffect($effect) { */ public function getEffects() { if (!$this->effectsCollection) { - $this->effectsCollection = new ImageEffectPluginCollection($this->getImageEffectPluginManager(), $this->effects); + $this->effectsCollection = new ImageEffectPluginCollection($this->getImageEffectPluginManager(), $this, $this->effects); $this->effectsCollection->sort(); } return $this->effectsCollection; diff --git a/core/modules/image/src/ImageEffectBase.php b/core/modules/image/src/ImageEffectBase.php index 3b3bbb7..5731de1 100644 --- a/core/modules/image/src/ImageEffectBase.php +++ b/core/modules/image/src/ImageEffectBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; +use Drupal\image\ImageStyleInterface; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -39,6 +40,13 @@ protected $weight = ''; /** + * The image style of this effect. + * + * @var \Drupal\image\ImageStyleInterface + */ + protected $imageStyle = NULL; + + /** * A logger instance. * * @var \Psr\Log\LoggerInterface @@ -70,6 +78,21 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ + public function setImageStyle(ImageStyleInterface $image_style) { + $this->imageStyle = $image_style; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getImageStyle() { + return $this->imageStyle; + } + + /** + * {@inheritdoc} + */ public function transformDimensions(array &$dimensions) { $dimensions['width'] = $dimensions['height'] = NULL; } diff --git a/core/modules/image/src/ImageEffectPluginCollection.php b/core/modules/image/src/ImageEffectPluginCollection.php index ef17191..e9a9838 100644 --- a/core/modules/image/src/ImageEffectPluginCollection.php +++ b/core/modules/image/src/ImageEffectPluginCollection.php @@ -8,6 +8,8 @@ namespace Drupal\image; use Drupal\Core\Plugin\DefaultLazyPluginCollection; +use Drupal\image\ImageEffectManager; +use Drupal\image\ImageStyleInterface; /** * A collection of image effects. @@ -15,12 +17,37 @@ class ImageEffectPluginCollection extends DefaultLazyPluginCollection { /** + * The image style of this collection. + * + * @var \Drupal\image\ImageStyleInterface + */ + protected $imageStyle; + + /** + * Constructs a new ImageEffectPluginCollection object. + * + * @param \Drupal\image\ImageEffectManager $manager + * The image effect manager. + * @param \Drupal\image\ImageStyleInterface $image_style + * The image style of this collection. + * @param array $configurations + * (optional) An associative array containing the initial configuration for + * each plugin in the collection, keyed by plugin instance ID. + */ + public function __construct(ImageEffectManager $manager, ImageStyleInterface $image_style, array $configurations = array()) { + parent::__construct($manager, $configurations); + $this->imageStyle = $image_style; + } + + /** * {@inheritdoc} * * @return \Drupal\image\ImageEffectInterface */ public function &get($instance_id) { - return parent::get($instance_id); + $effect_plugin = parent::get($instance_id); + $effect_plugin->setImageStyle($this->imageStyle); + return $effect_plugin; } /** diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index b84c87d..7709009 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -149,6 +149,9 @@ function testStyle() { foreach ($effect_edits[$effect->getPluginId()] as $field => $value) { $this->assertEqual($value, $effect_configuration['data'][$field], String::format('The %field field in the %effect effect has the correct value of %value.', array('%field' => $field, '%effect' => $effect->getPluginId(), '%value' => $value))); } + // Check that ImageStyle third party settings are accessible from within + // the effect. + $this->assertEqual('bar', $effect->getImageStyle()->getThirdPartySetting('image_module_test', 'foo'), 'Image style third party settings are accessible from the effect.'); } // Assert that every effect was saved.