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

Issue #3017054 by alexpott, deviantintegral, percoction, mattwith,...

Issue #3017054 by alexpott, deviantintegral, percoction, mattwith, ankithashetty, Wim Leers, jwilson3, longwave, bircher: Consistently sort filter formats to simplify config exports

(cherry picked from commit 5f533ca6)
parent 90c16a3b
Loading
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -9,15 +9,12 @@ weight: 0
roles:
  - authenticated
filters:
  filter_html:
    id: filter_html
    provider: filter
  editor_file_reference:
    id: editor_file_reference
    provider: editor
    status: true
    weight: -10
    settings:
      allowed_html: '<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <p> <br> <span> <img src alt height width data-entity-type data-entity-uuid data-align data-caption>'
      filter_html_help: false
      filter_html_nofollow: false
    weight: 11
    settings: {  }
  filter_align:
    id: filter_align
    provider: filter
@@ -30,15 +27,18 @@ filters:
    status: true
    weight: 8
    settings: {  }
  filter_html:
    id: filter_html
    provider: filter
    status: true
    weight: -10
    settings:
      allowed_html: '<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <p> <br> <span> <img src alt height width data-entity-type data-entity-uuid data-align data-caption>'
      filter_html_help: false
      filter_html_nofollow: false
  filter_html_image_secure:
    id: filter_html_image_secure
    provider: filter
    status: true
    weight: 9
    settings: {  }
  editor_file_reference:
    id: editor_file_reference
    provider: editor
    status: true
    weight: 11
    settings: {  }
+6 −9
Original line number Diff line number Diff line
@@ -9,14 +9,18 @@ name: 'Plain text'
format: plain_text
weight: 10
filters:
  # Escape all HTML.
  filter_autop:
    id: filter_autop
    provider: filter
    status: true
    weight: 0
    settings: {  }
  filter_html_escape:
    id: filter_html_escape
    provider: filter
    status: true
    weight: -10
    settings: {  }
  # Convert URLs into links.
  filter_url:
    id: filter_url
    provider: filter
@@ -24,10 +28,3 @@ filters:
    weight: 0
    settings:
      filter_url_length: 72
  # Convert linebreaks into paragraphs.
  filter_autop:
    id: filter_autop
    provider: filter
    status: true
    weight: 0
    settings: {  }
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ filter.format.*:
        label: 'Role'
    filters:
      type: sequence
      orderby: key
      label: 'Enabled filters'
      sequence:
        type: filter
+21 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Post update functions for Filter.
 */

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

/**
 * Sorts filter format filter configuration.
 */
function filter_post_update_sort_filters(?array &$sandbox = NULL): void {
  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
  $config_entity_updater->update($sandbox, 'filter_format', function (FilterFormat $format): bool {
    $sorted_filters = $filters = array_keys($format->get('filters'));
    sort($sorted_filters);
    return $sorted_filters !== $filters;
  });
}
+6 −3
Original line number Diff line number Diff line
@@ -202,10 +202,13 @@ public function disable() {
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage) {
    // Ensure the filters have been sorted before saving.
    $this->filters()->sort();

    parent::preSave($storage);
    if (!$this->isSyncing() && $this->hasTrustedData()) {
      // Filters are sorted by keys to ensure config export diffs are easy to
      // read and there is a minimal changeset. If the save is not trusted then
      // the configuration will be sorted by StorableConfigBase.
      ksort($this->filters);
    }

    assert(is_string($this->label()), 'Filter format label is expected to be a string.');
    $this->name = trim($this->label());
Loading