Loading core/modules/filter/config/schema/filter.schema.yml +3 −7 Original line number Diff line number Diff line Loading @@ -46,14 +46,11 @@ filter.format.*: label: 'Dependencies' filter_settings.*: type: sequence type: mapping label: 'Filter settings' sequence: type: string label: 'Value' filter_settings.filter_html: type: filter type: mapping label: 'Filter HTML' mapping: allowed_html: Loading @@ -66,9 +63,8 @@ filter_settings.filter_html: type: boolean label: 'HTML nofollow' filter_settings.filter_url: type: filter type: mapping label: 'Filter URL' mapping: filter_url_length: Loading core/modules/filter/filter.post_update.php +15 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\filter\Entity\FilterFormat; use Drupal\filter\FilterFormatInterface; /** * Sorts filter format filter configuration. Loading @@ -19,3 +20,17 @@ function filter_post_update_sort_filters(?array &$sandbox = NULL): void { return $sorted_filters !== $filters; }); } /** * Change filter_settings to type mapping. */ function filter_post_update_consolidate_filter_config(?array &$sandbox = NULL): void { \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'filter_format', function (FilterFormatInterface $format): bool { foreach ($format->get('filters') as $config) { if (empty($config['id']) || empty($config['provider'])) { return TRUE; } } return FALSE; }); } core/modules/filter/src/Entity/FilterFormat.php +5 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,11 @@ public function preSave(EntityStorageInterface $storage) { // read and there is a minimal changeset. If the save is not trusted then // the configuration will be sorted by StorableConfigBase. ksort($this->filters); // Ensure the filter configuration is well-formed. array_walk($this->filters, function (array &$config, string $filter): void { $config['id'] ??= $filter; $config['provider'] ??= $this->filters($filter)->getPluginDefinition()['provider']; }); } assert(is_string($this->label()), 'Filter format label is expected to be a string.'); Loading core/modules/filter/src/FilterFormatFormBase.php +14 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,20 @@ public function form(array $form, FormStateInterface $form_state) { '#attributes' => ['class' => ['filter-order-weight']], ]; // Ensure the resulting FilterFormat complies with `type: filter`. // @see core.data_types.schema.yml // @see \Drupal\filter\FilterFormatFormBase::submitForm() $form['filters']['order'][$name]['id'] = [ '#type' => 'value', '#value' => $filter->getPluginId(), '#parents' => ['filters', $name, 'id'], ]; $form['filters']['order'][$name]['provider'] = [ '#type' => 'value', '#value' => $filter->provider, '#parents' => ['filters', $name, 'provider'], ]; // Retrieve the settings form of the filter plugin. The plugin should not be // aware of the text format. Therefore, it only receives a set of minimal // base properties to allow advanced implementations to work. Loading core/modules/filter/tests/filter_test/config/schema/filter_test.schema.yml +1 −1 Original line number Diff line number Diff line # Schema for the configuration files of the Filter test module. filter_settings.filter_test_restrict_tags_and_attributes: type: filter type: mapping label: 'Filter to restrict HTML tags and attributes' mapping: restrictions: Loading Loading
core/modules/filter/config/schema/filter.schema.yml +3 −7 Original line number Diff line number Diff line Loading @@ -46,14 +46,11 @@ filter.format.*: label: 'Dependencies' filter_settings.*: type: sequence type: mapping label: 'Filter settings' sequence: type: string label: 'Value' filter_settings.filter_html: type: filter type: mapping label: 'Filter HTML' mapping: allowed_html: Loading @@ -66,9 +63,8 @@ filter_settings.filter_html: type: boolean label: 'HTML nofollow' filter_settings.filter_url: type: filter type: mapping label: 'Filter URL' mapping: filter_url_length: Loading
core/modules/filter/filter.post_update.php +15 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\filter\Entity\FilterFormat; use Drupal\filter\FilterFormatInterface; /** * Sorts filter format filter configuration. Loading @@ -19,3 +20,17 @@ function filter_post_update_sort_filters(?array &$sandbox = NULL): void { return $sorted_filters !== $filters; }); } /** * Change filter_settings to type mapping. */ function filter_post_update_consolidate_filter_config(?array &$sandbox = NULL): void { \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'filter_format', function (FilterFormatInterface $format): bool { foreach ($format->get('filters') as $config) { if (empty($config['id']) || empty($config['provider'])) { return TRUE; } } return FALSE; }); }
core/modules/filter/src/Entity/FilterFormat.php +5 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,11 @@ public function preSave(EntityStorageInterface $storage) { // read and there is a minimal changeset. If the save is not trusted then // the configuration will be sorted by StorableConfigBase. ksort($this->filters); // Ensure the filter configuration is well-formed. array_walk($this->filters, function (array &$config, string $filter): void { $config['id'] ??= $filter; $config['provider'] ??= $this->filters($filter)->getPluginDefinition()['provider']; }); } assert(is_string($this->label()), 'Filter format label is expected to be a string.'); Loading
core/modules/filter/src/FilterFormatFormBase.php +14 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,20 @@ public function form(array $form, FormStateInterface $form_state) { '#attributes' => ['class' => ['filter-order-weight']], ]; // Ensure the resulting FilterFormat complies with `type: filter`. // @see core.data_types.schema.yml // @see \Drupal\filter\FilterFormatFormBase::submitForm() $form['filters']['order'][$name]['id'] = [ '#type' => 'value', '#value' => $filter->getPluginId(), '#parents' => ['filters', $name, 'id'], ]; $form['filters']['order'][$name]['provider'] = [ '#type' => 'value', '#value' => $filter->provider, '#parents' => ['filters', $name, 'provider'], ]; // Retrieve the settings form of the filter plugin. The plugin should not be // aware of the text format. Therefore, it only receives a set of minimal // base properties to allow advanced implementations to work. Loading
core/modules/filter/tests/filter_test/config/schema/filter_test.schema.yml +1 −1 Original line number Diff line number Diff line # Schema for the configuration files of the Filter test module. filter_settings.filter_test_restrict_tags_and_attributes: type: filter type: mapping label: 'Filter to restrict HTML tags and attributes' mapping: restrictions: Loading