Commit a6274c0f authored by xjm's avatar xjm

Issue #2350569 by webflo, alexpott, tim.plunkett: Allow external update of...

Issue #2350569 by webflo, alexpott, tim.plunkett: Allow external update of ConfigEntity properties that are associated with a PluginCollection
parent 28f30021
......@@ -133,8 +133,18 @@ public function getConfiguration() {
* {@inheritdoc}
*/
public function setConfiguration($configuration) {
// Track each instance ID as it is updated.
$unprocessed_instance_ids = $this->getInstanceIds();
foreach ($configuration as $instance_id => $instance_configuration) {
$this->setInstanceConfiguration($instance_id, $instance_configuration);
// Remove this instance ID from the list being updated.
unset($unprocessed_instance_ids[$instance_id]);
}
// Remove remaining instances that had no configuration specified for them.
foreach ($unprocessed_instance_ids as $unprocessed_instance_id) {
$this->removeInstanceId($unprocessed_instance_id);
}
return $this;
}
......
<?php
/**
* @file
* Contains \Drupal\image\Tests\ImageImportTest.
*/
namespace Drupal\image\Tests;
use Drupal\image\Entity\ImageStyle;
use Drupal\simpletest\KernelTestBase;
/**
* Tests config import for Image styles.
*
* @group image
*/
class ImageImportTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'image', 'image_module_test'];
/**
* Tests importing image styles.
*/
public function testImport() {
$style = ImageStyle::create([
'name' => 'test'
]);
$style->addImageEffect(['id' => 'image_module_test_null']);
$style->addImageEffect(['id' => 'image_module_test_null']);
$style->save();
$this->assertEqual(count($style->getEffects()), 2);
$uuid = \Drupal::service('uuid')->generate();
$style->set('effects', [
$uuid => [
'id' => 'image_module_test_null',
],
]);
$style->save();
$style = ImageStyle::load('test');
$this->assertEqual(count($style->getEffects()), 1);
}
}
......@@ -224,16 +224,19 @@ public function testConfigurableGetConfiguration() {
* @covers ::setConfiguration
*/
public function testConfigurableSetConfiguration() {
$this->setupPluginCollection($this->exactly(3));
$this->defaultPluginCollection->getConfiguration();
$this->defaultPluginCollection->setInstanceConfiguration('apple', array('value' => 'pineapple'));
$this->setupPluginCollection($this->exactly(2));
$expected = $this->config;
$expected['apple'] = array('value' => 'pineapple');
$this->defaultPluginCollection->setConfiguration(['apple' => ['value' => 'pineapple', 'id' => 'apple']]);
$config = $this->defaultPluginCollection->getConfiguration();
$this->assertSame($expected, $config);
$this->assertSame(['apple' => ['value' => 'pineapple', 'id' => 'apple']], $config);
$plugin = $this->pluginInstances['apple'];
$this->assertSame($expected['apple'], $plugin->getConfiguration());
$this->assertSame(['value' => 'pineapple', 'id' => 'apple'], $plugin->getConfiguration());
$this->defaultPluginCollection->setConfiguration(['cherry' => ['value' => 'kiwi', 'id' => 'cherry']]);
$expected['cherry'] = ['value' => 'kiwi', 'id' => 'cherry'];
$config = $this->defaultPluginCollection->getConfiguration();
$this->assertSame(['cherry' => ['value' => 'kiwi', 'id' => 'cherry']], $config);
}
}
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