diff --git a/core/modules/config/src/Tests/ConfigSchemaTest.php b/core/modules/config/src/Tests/ConfigSchemaTest.php index fae39233d210884c42244eca0d644b0c36fdc7f8..5dbec3597e516858e2c3db82855e6234fe345d4c 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 4f1fc7919d193600c05fdf3890895dc44a285320..88075cfa84fd697c128e25b678cd49768b5c64fc 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 450689122dc935f2f4e860e490ce1ca1afbec7e3..2e77f7f341e296e4f71f66a88c55d47a36dacbc9 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 fa14faf227501be2c89e6d25734f6d14e5aa83a3..7475b03d0c5004c25efa71048face95552fd397a 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 105187214a52494c315415c13dc841f911a75524..75b8843618fce1ef87d86e5f317429904ddb1dbd 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -129,6 +129,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 561737ad8ec2bbdc185ea33d6de2bc5c59bce02c..64b912e6d8837ce0e10cc98377f88dcbc0c5967a 100644 --- a/core/modules/image/src/Tests/ImageFieldTestBase.php +++ b/core/modules/image/src/Tests/ImageFieldTestBase.php @@ -32,7 +32,7 @@ abstract class ImageFieldTestBase extends WebTestBase { * * @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 0000000000000000000000000000000000000000..a36719d703156e38257dfe4a89514459cefd7820 --- /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.info.yml b/core/modules/image/tests/modules/image_module_test/image_module_test.info.yml index 9abaf4730cfb29925550630e98bb5c62ea512fb1..7c4d3ace4e2e44321d4bef9ce46e81c8bde26f9d 100644 --- a/core/modules/image/tests/modules/image_module_test/image_module_test.info.yml +++ b/core/modules/image/tests/modules/image_module_test/image_module_test.info.yml @@ -1,6 +1,6 @@ name: 'Image test' type: module description: 'Provides hook implementations for testing Image module functionality.' -package: Core +package: Testing version: VERSION core: 8.x 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 0242f1e7ff6ca9e8f72dc8cd9836fe15109bff11..df713753568391338ebb8c75101e69bc6a29e8b9 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'); +}