function EditorHooks::filterFormatPresave

Implements hook_ENTITY_TYPE_presave().

Synchronizes the editor status to its paired text format status.

@todo remove in https://www.drupal.org/project/drupal/issues/3231354.

Attributes

#[Hook('filter_format_presave')]

File

core/modules/editor/src/Hook/EditorHooks.php, line 333

Class

EditorHooks
Hook implementations for editor.

Namespace

Drupal\editor\Hook

Code

public function filterFormatPresave(FilterFormatInterface $format) : void {
  // The text format being created cannot have a text editor yet.
  if ($format->isNew()) {
    return;
  }
  /** @var \Drupal\filter\FilterFormatInterface $original */
  $original = \Drupal::entityTypeManager()->getStorage('filter_format')
    ->loadUnchanged($format->getOriginalId());
  // If the text format status is the same, return early.
  if (($status = $format->status()) === $original->status()) {
    return;
  }
  /** @var \Drupal\editor\EditorInterface $editor */
  if ($editor = Editor::load($format->id())) {
    $editor->setStatus($status)
      ->save();
  }
}

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