You are here

editor_test.module in Drupal 8

Same filename and directory in other branches
  1. 9 core/modules/editor/tests/modules/editor_test.module

Helper module for the Text Editor tests.

File

core/modules/editor/tests/modules/editor_test.module
View source
<?php

/**
 * @file
 * Helper module for the Text Editor tests.
 */
use Drupal\filter\FilterFormatInterface;
use Drupal\file\FileInterface;

/**
 * Implements hook_editor_js_settings_alter().
 */
function editor_test_editor_js_settings_alter(&$settings) {

  // Allow tests to enable or disable this alter hook.
  if (!\Drupal::state()
    ->get('editor_test_js_settings_alter_enabled', FALSE)) {
    return;
  }
  if (isset($settings['editor']['formats']['full_html'])) {
    $settings['editor']['formats']['full_html']['editorSettings']['ponyModeEnabled'] = FALSE;
  }
}

/**
 * Implements hook_editor_xss_filter_alter().
 */
function editor_test_editor_xss_filter_alter(&$editor_xss_filter_class, FilterFormatInterface $format, FilterFormatInterface $original_format = NULL) {

  // Allow tests to enable or disable this alter hook.
  if (!\Drupal::state()
    ->get('editor_test_editor_xss_filter_alter_enabled', FALSE)) {
    return;
  }
  $filters = $format
    ->filters()
    ->getAll();
  if (isset($filters['filter_html']) && $filters['filter_html']->status) {
    $editor_xss_filter_class = '\\Drupal\\editor_test\\EditorXssFilter\\Insecure';
  }
}

/**
 * Implements hook_editor_info_alter().
 */
function editor_test_editor_info_alter(&$items) {
  if (!\Drupal::state()
    ->get('editor_test_give_me_a_trex_thanks', FALSE)) {
    unset($items['trex']);
  }
}

/**
 * Implements hook_ENTITY_TYPE_presave() for file entities.
 */
function editor_test_file_presave(FileInterface $file) {

  // Use state to keep track of how many times a file is saved.
  $file_save_count = \Drupal::state()
    ->get('editor_test.file_save_count', []);
  $file_save_count[$file
    ->getFilename()] = isset($file_save_count[$file
    ->getFilename()]) ? $file_save_count[$file
    ->getFilename()] + 1 : 1;
  \Drupal::state()
    ->set('editor_test.file_save_count', $file_save_count);
}