function FilterFormat::preSave

Same name in other branches
  1. 9 core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::preSave()
  2. 8.9.x core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::preSave()
  3. 11.x core/modules/filter/src/Entity/FilterFormat.php \Drupal\filter\Entity\FilterFormat::preSave()

Overrides ConfigEntityBase::preSave

File

core/modules/filter/src/Entity/FilterFormat.php, line 207

Class

FilterFormat
Represents a text format.

Namespace

Drupal\filter\Entity

Code

public function preSave(EntityStorageInterface $storage) {
    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);
        // 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.');
    $this->name = trim($this->label());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.