Verified Commit d8c4e4cf authored by Dave Long's avatar Dave Long
Browse files

Issue #3404431 by claudiu.cristea, Wim Leers, borisson_, quietone: Filter...

Issue #3404431 by claudiu.cristea, Wim Leers, borisson_, quietone: Filter settings schema types are incorrect
parent e1312a3d
Loading
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -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:
@@ -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:
+15 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\filter\Entity\FilterFormat;
use Drupal\filter\FilterFormatInterface;

/**
 * Sorts filter format filter configuration.
@@ -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;
  });
}
+5 −0
Original line number Diff line number Diff line
@@ -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.');
+14 −0
Original line number Diff line number Diff line
@@ -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.
+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