From 73b0592ffe271b1c8183ccbca20cd06817da5cf0 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 9 Sep 2014 11:05:34 +0100 Subject: [PATCH] Issue #2084985 by mondrake: Added Implement ThirdPartySettingsInterface in ImageStyle. --- core/modules/config/src/Tests/ConfigSchemaTest.php | 3 +++ core/modules/image/config/schema/image.schema.yml | 5 +++++ core/modules/image/src/Entity/ImageStyle.php | 3 +++ core/modules/image/src/ImageStyleInterface.php | 3 ++- core/modules/image/src/Tests/ImageAdminStylesTest.php | 6 ++++++ core/modules/image/src/Tests/ImageFieldTestBase.php | 2 +- .../config/schema/image_module_test.schema.yml | 7 +++++++ .../image_module_test/image_module_test.info.yml | 2 +- .../image_module_test/image_module_test.module | 11 +++++++++++ 9 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml diff --git a/core/modules/config/src/Tests/ConfigSchemaTest.php b/core/modules/config/src/Tests/ConfigSchemaTest.php index fae39233d210884..5dbec3597e51685 100644 --- a/core/modules/config/src/Tests/ConfigSchemaTest.php +++ b/core/modules/config/src/Tests/ConfigSchemaTest.php @@ -166,6 +166,9 @@ class ConfigSchemaTest extends DrupalUnitTestBase { $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 4f1fc7919d19360..88075cfa84fd697 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 450689122dc935f..2e77f7f341e296e 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -9,6 +9,7 @@ namespace Drupal\image\Entity; 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 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; */ 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 fa14faf227501be..7475b03d0c5004c 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 105187214a52494..75b8843618fce1e 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -129,6 +129,12 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // 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 561737ad8ec2bbd..64b912e6d8837ce 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 000000000000000..a36719d703156e3 --- /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 9abaf4730cfb299..7c4d3ace4e2e443 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 0242f1e7ff6ca9e..df7137535683913 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'); +}