Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
26 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #87809 passed
Pipeline: drupal

#87811

    ......@@ -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:
    ......
    ......@@ -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;
    });
    }
    ......@@ -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.');
    ......
    ......@@ -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.
    ......
    # 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:
    ......
    <?php
    /**
    * @file
    * Fixture file to test filter_post_update_consolidate_filter_config().
    *
    * @see https://www.drupal.org/project/drupal/issues/3404431
    * @see \Drupal\Tests\filter\Functional\FilterFormatConsolidateFilterConfigUpdateTest
    * @see filter_post_update_consolidate_filter_config()
    */
    use Drupal\Core\Database\Database;
    $db = Database::getConnection();
    $format = unserialize($db->select('config')
    ->fields('config', ['data'])
    ->condition('collection', '')
    ->condition('name', 'filter.format.plain_text')
    ->execute()
    ->fetchField());
    unset($format['filters']['filter_autop']['id']);
    unset($format['filters']['filter_html_escape']['provider']);
    unset($format['filters']['filter_url']['id']);
    unset($format['filters']['filter_url']['provider']);
    $db->update('config')
    ->fields(['data' => serialize($format)])
    ->condition('collection', '')
    ->condition('name', 'filter.format.plain_text')
    ->execute();
    <?php
    namespace Drupal\Tests\filter\Functional;
    use Drupal\FunctionalTests\Update\UpdatePathTestBase;
    /**
    * Tests the upgrade path for filter formats.
    *
    * @see filter_post_update_consolidate_filter_config()
    *
    * @group Update
    * @group legacy
    */
    class FilterFormatConsolidateFilterConfigUpdateTest extends UpdatePathTestBase {
    /**
    * {@inheritdoc}
    */
    protected function setDatabaseDumpFiles(): void {
    $this->databaseDumpFiles = [
    __DIR__ . '/../../../../system/tests/fixtures/update/drupal-9.4.0.bare.standard.php.gz',
    __DIR__ . '/../../fixtures/update/filter_post_update_consolidate_filter_config-3404431.php',
    ];
    }
    /**
    * @covers \filter_post_update_consolidate_filter_config
    */
    public function testConsolidateFilterConfig() {
    $format = $this->config('filter.format.plain_text');
    $this->assertArrayNotHasKey('id', $format->get('filters.filter_autop'));
    $this->assertSame('filter', $format->get('filters.filter_autop.provider'));
    $this->assertSame('filter_html_escape', $format->get('filters.filter_html_escape.id'));
    $this->assertArrayNotHasKey('provider', $format->get('filters.filter_html_escape'));
    $this->assertArrayNotHasKey('id', $format->get('filters.filter_url'));
    $this->assertArrayNotHasKey('provider', $format->get('filters.filter_url'));
    $this->runUpdates();
    $format = $this->config('filter.format.plain_text');
    $this->assertSame('filter_autop', $format->get('filters.filter_autop.id'));
    $this->assertSame('filter', $format->get('filters.filter_autop.provider'));
    $this->assertSame('filter_html_escape', $format->get('filters.filter_html_escape.id'));
    $this->assertSame('filter', $format->get('filters.filter_html_escape.provider'));
    $this->assertSame('filter_url', $format->get('filters.filter_url.id'));
    $this->assertSame('filter', $format->get('filters.filter_url.provider'));
    }
    }
    ......@@ -119,7 +119,7 @@ media.source.field_aware:
    label: 'Source field'
    filter_settings.media_embed:
    type: filter
    type: mapping
    label: 'Media Embed'
    mapping:
    default_view_mode:
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment