diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index 94a5bb3..8bda458 100644 --- a/core/modules/filter/src/Entity/FilterFormat.php +++ b/core/modules/filter/src/Entity/FilterFormat.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Entity; +use Drupal\Component\Utility\DiffArray; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityWithPluginBagsInterface; use Drupal\Core\Entity\EntityStorageInterface; @@ -200,7 +201,7 @@ public function preSave(EntityStorageInterface $storage) { if (!$filter['status']) { // Compare the current settings to the default settings. If there are // any customisations save them to configuration. - $diff = array_diff($filter, $default); + $diff = DiffArray::diffAssocRecursive($filter, $default); return !empty($diff); } return TRUE; diff --git a/core/modules/filter/src/Tests/FilterAPITest.php b/core/modules/filter/src/Tests/FilterAPITest.php index 2c5522a..383a7c0 100644 --- a/core/modules/filter/src/Tests/FilterAPITest.php +++ b/core/modules/filter/src/Tests/FilterAPITest.php @@ -335,6 +335,50 @@ function testTypedDataAPI() { } /** + * Tests that FilterFormat::preSave() only saves customised plugins. + */ + public function testFilterFormatPreSave() { + /** @var \Drupal\filter\FilterFormatInterface $crazy_format */ + $crazy_format = entity_create('filter_format', array( + 'format' => 'crazy', + 'name' => 'Crazy', + 'weight' => 1, + 'filters' => array( + 'filter_html_escape' => array( + 'weight' => 10, + 'status' => 1, + ), + 'filter_html' => array( + 'weight' => -10, + 'status' => 1, + 'settings' => array( + 'allowed_html' => '

', + ), + ), + ) + )); + $crazy_format->save(); + // Use config to directly load the configuration and check that only enabled + // or customised plugins are saved to configuration. + $filters = \Drupal::config('filter.format.crazy')->get('filters'); + $this->assertEqual(array('filter_html_escape', 'filter_html'), array_keys($filters)); + + // Disable a plugin to ensure that disabled plugins with custom settings are + // stored in configuration. + $crazy_format->setFilterConfig('filter_html_escape', array('status' => FALSE)); + $crazy_format->save(); + $filters = \Drupal::config('filter.format.crazy')->get('filters'); + $this->assertEqual(array('filter_html_escape', 'filter_html'), array_keys($filters)); + + // Set the settings as per default to ensure that disable plugins in this + // state are not stored in configuration. + $crazy_format->setFilterConfig('filter_html_escape', array('weight' => -10)); + $crazy_format->save(); + $filters = \Drupal::config('filter.format.crazy')->get('filters'); + $this->assertEqual(array('filter_html'), array_keys($filters)); + } + + /** * Checks if an expected violation exists in the given violations. * * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations