You are here

ckeditor_config.install in CKEditor custom config 8.3

Same filename and directory in other branches
  1. 8.2 ckeditor_config.install

Install, update and uninstall functions for the ckeditor_config module.

File

ckeditor_config.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the ckeditor_config module.
 */
use Drupal\user\Entity\Role;

/**
 * Move global config to individual CKEditor editors. Delete disused permission.
 */
function ckeditor_config_update_8200() {

  // Load configuration from 8.x-1.x.
  $config_previous = \Drupal::service('config.factory')
    ->get('ckeditor_config.config_form')
    ->get('config');

  // Loop through all text formats.
  $filter_formats = filter_formats();
  foreach ($filter_formats as $filter_name => $filter_format) {
    $editor = editor_load($filter_name);
    if (is_null($editor)) {
      continue;
    }
    $editor_name = $editor
      ->getEditor();

    // Only proceed if the editor is 'ckeditor'.
    if ($editor_name == 'ckeditor') {
      $config = \Drupal::service('config.factory')
        ->getEditable('editor.editor.' . $filter_name);
      $settings = $config
        ->get('settings');
      $settings['plugins']['customconfig']['ckeditor_custom_config'] = $config_previous;
      $config
        ->set('settings', $settings)
        ->save();
    }
  }

  // Delete configuration from 8.x-1.x.
  \Drupal::service('config.factory')
    ->getEditable('ckeditor_config.config_form')
    ->delete();

  // Loop through roles and revoke disused permission.
  $roles = Role::loadMultiple();
  foreach ($roles as $role) {
    $role
      ->revokePermission('ckeditor config')
      ->save();
  }
}

/**
 * Implements hook_uninstall().
 */
function ckeditor_config_uninstall() {

  // Loop through all text formats.
  $filter_formats = filter_formats();
  foreach ($filter_formats as $filter_name => $filter_format) {
    $editor = editor_load($filter_name);
    if (is_null($editor)) {
      continue;
    }
    $editor_name = $editor
      ->getEditor();

    // Only proceed if the editor is 'ckeditor'.
    if ($editor_name == 'ckeditor') {
      $config = \Drupal::service('config.factory')
        ->getEditable('editor.editor.' . $filter_name);
      $settings = $config
        ->get('settings');

      // Remove 'customconfig' settings.
      if (isset($settings['plugins']['customconfig'])) {
        unset($settings['plugins']['customconfig']);
        $config
          ->set('settings', $settings)
          ->save();
      }
    }
  }
}

Functions

Namesort descending Description
ckeditor_config_uninstall Implements hook_uninstall().
ckeditor_config_update_8200 Move global config to individual CKEditor editors. Delete disused permission.