You are here

class FilterFormatEditor in Acquia Content Hub 8.2

Handles FilterFormatEditor entity saves to apply related schema.

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\EntityImport\FilterFormatEditor implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of FilterFormatEditor

1 string reference to 'FilterFormatEditor'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses FilterFormatEditor
filter_format.entity.import in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\EntityImport\FilterFormatEditor

File

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

Namespace

Drupal\acquia_contenthub\EventSubscriber\EntityImport
View source
class FilterFormatEditor implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::ENTITY_IMPORT_NEW][] = 'onImportNew';
    $events[AcquiaContentHubEvents::ENTITY_IMPORT_UPDATE][] = 'onImportNew';
    return $events;
  }

  /**
   * Ensures an editor exists for a filter format.
   *
   * @param \Drupal\acquia_contenthub\Event\EntityImportEvent $event
   *   The entity import event.
   *
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FilterFormatEditor::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
FilterFormatEditor::onImportNew public function Ensures an editor exists for a filter format.