You are here

varbase_editor.install in Varbase Editor 8.4

Install, update and uninstall functions for the Varbase editor module.

File

varbase_editor.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Varbase editor module.
 */
use Symfony\Component\Yaml\Yaml;
use Drupal\filter\Entity\FilterFormat;

/**
 * WARNING:
 * The "Full HTML" text format was mistakenly referred to by its machine name (restricted_html), this is confusing and wrong. Therefore, this filter has been deprecated in favor of better naming to become "HTML code" (code_html).
 * Please make sure to revise your content if it was using the "Full HTML" text format. You can enable it again if you like, or switch to use the new "HTML code" text format.
 */
function varbase_editor_update_8001() {

  // Enable HTML code text format (code_html).
  $code_html_editor_config = \Drupal::service('config.factory')
    ->getEditable('editor.editor.code_html');
  $code_html_editor_config_file = \Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/editor.editor.code_html.yml';
  $code_html_editor_config_content = file_get_contents($code_html_editor_config_file);
  $code_html_editor_config_content_data = (array) Yaml::parse($code_html_editor_config_content);
  $code_html_editor_config
    ->setData($code_html_editor_config_content_data)
    ->save();
  $code_html_format_config = \Drupal::service('config.factory')
    ->getEditable('filter.format.code_html');
  $code_html_format_config_file = \Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/filter.format.code_html.yml';
  $code_html_format_config_content = file_get_contents($code_html_format_config_file);
  $code_html_format_config_content_data = (array) Yaml::parse($code_html_format_config_content);
  $code_html_format_config
    ->setData($code_html_format_config_content_data)
    ->save();
  if (file_exists(\Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/filter.format.restricted_html.yml')) {

    // Disable Full HTML text format (restricted_html).
    $restricted_html_format_config = \Drupal::service('config.factory')
      ->getEditable('filter.format.restricted_html');
    $restricted_html_format_config_file = \Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/filter.format.restricted_html.yml';
    $restricted_html_format_config_content = file_get_contents($restricted_html_format_config_file);
    $restricted_html_format_config_content_data = (array) Yaml::parse($restricted_html_format_config_content);
    $restricted_html_format_config
      ->setData($restricted_html_format_config_content_data)
      ->save();
    $restricted_html_editor_config = \Drupal::service('config.factory')
      ->getEditable('editor.editor.restricted_html');
    $restricted_html_editor_config_file = \Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/editor.editor.restricted_html.yml';
    $restricted_html_editor_config_content = file_get_contents($restricted_html_editor_config_file);
    $restricted_html_editor_config_content_data = (array) Yaml::parse($restricted_html_editor_config_content);
    $restricted_html_editor_config
      ->setData($restricted_html_editor_config_content_data)
      ->save();
    $update_message = t('<b>WARNING:</b><br /><p>The "Full HTML" text format was mistakenly referred to by its machine name (restricted_html), this is confusing and wrong. Therefore, this filter has been deprecated in favor of better naming to become "HTML code" (code_html).</p><p>Please make sure to revise your content if it was using the "Full HTML" text format. You can enable it again if you like, or switch to use the new "HTML code" text format.</p>');
    \Drupal::logger('varbase_editor')
      ->notice($update_message);
    drupal_set_message($update_message, 'warning');
  }
}

/**
 * Enable pathologic module.
 * Enable image resize filter module.
 * Enable ckeditor bidi module.
 * Enable pathologic module.
 */
function varbase_editor_update_8002() {

  // Enable pathologic module.
  if (!\Drupal::moduleHandler()
    ->moduleExists('pathologic')) {
    \Drupal::service('module_installer')
      ->install([
      'pathologic',
    ], FALSE);
  }

  // Enable image resize filter module.
  if (!\Drupal::moduleHandler()
    ->moduleExists('image_resize_filter')) {
    \Drupal::service('module_installer')
      ->install([
      'image_resize_filter',
    ], FALSE);
  }

  // Enable ckeditor bidi module.
  if (!\Drupal::moduleHandler()
    ->moduleExists('ckeditor_bidi')) {
    \Drupal::service('module_installer')
      ->install([
      'ckeditor_bidi',
    ], FALSE);
  }

  // Enable pathologic module.
  if (!\Drupal::moduleHandler()
    ->moduleExists('pathologic')) {
    \Drupal::service('module_installer')
      ->install([
      'pathologic',
    ], FALSE);
  }
}

/**
 * Enable CKEditor media embed module.
 */
function varbase_editor_update_8003() {
  if (!\Drupal::moduleHandler()
    ->moduleExists('ckeditor_media_embed')) {
    \Drupal::service('module_installer')
      ->install([
      'ckeditor_media_embed',
    ], FALSE);
  }
}

/**
 * Update "Rich editor" to use the CKEditor media embed button.
 */
function varbase_editor_update_8004() {

  // Update "Rich editor" editor config.
  $full_html_editor_config = \Drupal::service('config.factory')
    ->getEditable('editor.editor.full_html');
  $full_html_editor_config_file = \Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/editor.editor.full_html.yml';
  $full_html_editor_config_content = file_get_contents($full_html_editor_config_file);
  $full_html_editor_config_content_data = (array) Yaml::parse($full_html_editor_config_content);
  $full_html_editor_config
    ->setData($full_html_editor_config_content_data)
    ->save();

  // Update "Rich editor" filter format config.
  $full_html_format_config = \Drupal::service('config.factory')
    ->getEditable('filter.format.full_html');
  $full_html_format_config_file = \Drupal::root() . '/' . drupal_get_path('module', 'varbase_editor') . '/config/install/filter.format.full_html.yml';
  $full_html_format_config_content = file_get_contents($full_html_format_config_file);
  $full_html_format_config_content_data = (array) Yaml::parse($full_html_format_config_content);
  $full_html_format_config
    ->setData($full_html_format_config_content_data)
    ->save();
}

Functions

Namesort descending Description
varbase_editor_update_8001 WARNING: The "Full HTML" text format was mistakenly referred to by its machine name (restricted_html), this is confusing and wrong. Therefore, this filter has been deprecated in favor of better naming to become "HTML code"…
varbase_editor_update_8002 Enable pathologic module. Enable image resize filter module. Enable ckeditor bidi module. Enable pathologic module.
varbase_editor_update_8003 Enable CKEditor media embed module.
varbase_editor_update_8004 Update "Rich editor" to use the CKEditor media embed button.