Commit 73b0592f authored by alexpott's avatar alexpott

Issue #2084985 by mondrake: Added Implement ThirdPartySettingsInterface in ImageStyle.

parent d60d5be0
......@@ -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);
......
......@@ -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
......
......@@ -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.
*
......
......@@ -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.
......
......@@ -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.');
......
......@@ -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;
......
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'
name: 'Image test'
type: module
description: 'Provides hook implementations for testing Image module functionality.'
package: Core
package: Testing
version: VERSION
core: 8.x
......@@ -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');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment