diff --git a/core/modules/config/src/Tests/ConfigSchemaTest.php b/core/modules/config/src/Tests/ConfigSchemaTest.php index fae3923..5dbec35 100644 --- a/core/modules/config/src/Tests/ConfigSchemaTest.php +++ b/core/modules/config/src/Tests/ConfigSchemaTest.php @@ -166,6 +166,9 @@ function testSchemaMapping() { $expected['mapping']['effects']['sequence'][0]['mapping']['data']['type'] = 'image.effect.[%parent.id]'; $expected['mapping']['effects']['sequence'][0]['mapping']['weight']['type'] = 'integer'; $expected['mapping']['effects']['sequence'][0]['mapping']['uuid']['type'] = 'string'; + $expected['mapping']['third_party_settings']['type'] = 'sequence'; + $expected['mapping']['third_party_settings']['label'] = 'Third party settings'; + $expected['mapping']['third_party_settings']['sequence'][0]['type'] = 'image_style.third_party.[%key]'; $expected['type'] = 'image.style.*'; $this->assertEqual($definition, $expected); diff --git a/core/modules/image/config/schema/image.schema.yml b/core/modules/image/config/schema/image.schema.yml index 4f1fc79..88075cf 100644 --- a/core/modules/image/config/schema/image.schema.yml +++ b/core/modules/image/config/schema/image.schema.yml @@ -22,6 +22,11 @@ image.style.*: type: integer uuid: type: string + third_party_settings: + type: sequence + label: 'Third party settings' + sequence: + - type: image_style.third_party.[%key] image.effect.image_crop: type: image_size diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 4506891..2e77f7f 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Config\Entity\ThirdPartySettingsTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityWithPluginBagsInterface; use Drupal\Core\Routing\RequestHelper; @@ -50,6 +51,8 @@ */ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, EntityWithPluginBagsInterface { + use ThirdPartySettingsTrait; + /** * The name of the image style to use as replacement upon delete. * diff --git a/core/modules/image/src/ImageStyleInterface.php b/core/modules/image/src/ImageStyleInterface.php index fa14faf..7475b03 100644 --- a/core/modules/image/src/ImageStyleInterface.php +++ b/core/modules/image/src/ImageStyleInterface.php @@ -8,11 +8,12 @@ namespace Drupal\image; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Config\Entity\ThirdPartySettingsInterface; /** * Provides an interface defining an image style entity. */ -interface ImageStyleInterface extends ConfigEntityInterface { +interface ImageStyleInterface extends ConfigEntityInterface, ThirdPartySettingsInterface { /** * Returns the replacement ID. diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index d998883..5487078 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -124,6 +124,12 @@ function testStyle() { // Load the saved image style. $style = entity_load('image_style', $style_name); + + // Ensure that third party settings were added to the config entity. + // These are added by a hook_image_style_presave() implemented in + // image_module_test module. + $this->assertEqual('bar', $style->getThirdPartySetting('image_module_test', 'foo'), 'Third party settings were added to the image style.'); + // Ensure that the image style URI matches our expected path. $style_uri_path = $style->url(); $this->assertTrue(strpos($style_uri_path, $style_path) !== FALSE, 'The image style URI is correct.'); diff --git a/core/modules/image/src/Tests/ImageFieldTestBase.php b/core/modules/image/src/Tests/ImageFieldTestBase.php index 561737a..64b912e 100644 --- a/core/modules/image/src/Tests/ImageFieldTestBase.php +++ b/core/modules/image/src/Tests/ImageFieldTestBase.php @@ -32,7 +32,7 @@ * * @var array */ - public static $modules = array('node', 'image', 'field_ui'); + public static $modules = array('node', 'image', 'field_ui', 'image_module_test'); protected $admin_user; diff --git a/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml b/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml new file mode 100644 index 0000000..a36719d --- /dev/null +++ b/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml @@ -0,0 +1,7 @@ +image_style.third_party.image_module_test: + type: mapping + label: 'Schema for image_module_test module additions to image_style entity' + mapping: + foo: + type: string + label: 'Label for foo' diff --git a/core/modules/image/tests/modules/image_module_test/image_module_test.module b/core/modules/image/tests/modules/image_module_test/image_module_test.module index 0242f1e..df71375 100644 --- a/core/modules/image/tests/modules/image_module_test/image_module_test.module +++ b/core/modules/image/tests/modules/image_module_test/image_module_test.module @@ -5,6 +5,8 @@ * Provides Image module hook implementations for testing purposes. */ +use Drupal\image\ImageStyleInterface; + function image_module_test_file_download($uri) { $default_uri = \Drupal::state()->get('image.test_file_download') ?: FALSE; if ($default_uri == $uri) { @@ -21,3 +23,12 @@ function image_module_test_image_effect_info_alter(&$effects) { $image_effects_definition_called = &drupal_static(__FUNCTION__, 0); $image_effects_definition_called++; } + +/** + * Implements hook_image_style_presave(). + * + * Used to save test third party settings in the image style entity. + */ +function image_module_test_image_style_presave(ImageStyleInterface $style) { + $style->setThirdPartySetting('image_module_test', 'foo', 'bar'); +}