You are here

public function FilterFormatEditor::onImportNew in Acquia Content Hub 8.2

Ensures an editor exists for a filter format.

Parameters

\Drupal\acquia_contenthub\Event\EntityImportEvent $event: The entity import event.

Throws

\Drupal\Core\Entity\EntityStorageException

File

src/EventSubscriber/EntityImport/FilterFormatEditor.php, line 33

Class

FilterFormatEditor
Handles FilterFormatEditor entity saves to apply related schema.

Namespace

Drupal\acquia_contenthub\EventSubscriber\EntityImport

Code

public function onImportNew(EntityImportEvent $event) {
  if (!\Drupal::moduleHandler()
    ->moduleExists('editor')) {
    return;
  }
  $filter_format = $event
    ->getEntity();

  // Early return if this isn't the class of entity we care about.
  if (!$filter_format instanceof FilterFormat) {
    return;
  }
  if (editor_load($filter_format
    ->id())) {
    return;
  }
  $values = [
    'editor' => 'ckeditor',
    'format' => $filter_format
      ->id(),
  ];
  $editor = Editor::create($values);
  $editor
    ->save();
}