Change record status: 
Project: 
Introduced in branch: 
8.1.x
Description: 

ImageStyle config entities implement ThirdPartySettings interface and trait to enable contrib modules to store arbitrary values in the entity settings.

Image effects can now implement ImageStyleAwareInterface and ImageStyleAwareTrait in order to access third party settings stored on the ImageStyle they are part of.

This feature is normally not needed as image effects have their own settings/configuration storage. Only in specific cases where the settings are shared between style and effects or between effects, this comes in handy.

When an image-style-aware effect plugin is initialised by ImageStyle, ImageStyle injects itself in the ImageEffect, and the effect is able to access its parent' image style through a call to the getImageStyle() method.

Example:

/**
 * @file
 * Contains  \Drupal\mymodule\Plugin\ImageEffect\MymoduleImageStyleAwareEffect.
 */

namespace Drupal\mymodule\Plugin\ImageEffect;

use Drupal\Core\Image\ImageInterface;
use Drupal\image\ImageStyleAwareTrait;
use Drupal\image\ImageEffectBase;
use Drupal\image\ImageStyleAwareInterface;

/**
 * Provides an image-style-aware image effect.
 *
 * @ImageEffect(
 *   id = "mymodule_image_style_aware_effect",
 *   label = @Translation("My module image-style-aware effect")
 * )
 */
class MymoduleImageStyleAwareEffect extends ImageEffectBase implements ImageStyleAwareInterface {

  use ImageStyleAwareTrait;

  /**
   * {@inheritdoc}
   */
  public function applyEffect(ImageInterface $image) {

    ...

   $style_setting = $this->getImageStyle()->getThirdPartySetting('mymodule', 'style_setting'); 
   $image->apply('mymodule_operation', ['style_setting' => $style_setting]);

   ....

    return TRUE;
  }


}