filter.api.php 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * @file
 * Hooks provided by the Filter module.
 */

/**
 * @addtogroup hooks
 * @{
 */

13 14 15 16
/**
 * Perform alterations on filter definitions.
 *
 * @param $info
17
 *   Array of information on filters exposed by filter plugins.
18 19
 */
function hook_filter_info_alter(&$info) {
20
  // Alter the default settings of the URL filter provided by core.
21
  $info['filter_url']['default_settings'] = array(
22 23
    'filter_url_length' => 100,
  );
24 25
}

26 27 28 29 30 31 32 33 34 35 36 37
/**
 * Alters images with an invalid source.
 *
 * When the 'Restrict images to this site' filter is enabled, any images that
 * are not hosted on the site will be passed through this hook, most commonly to
 * replace the invalid image with an error indicator.
 *
 * @param DOMElement $image
 *   An IMG node to format, parsed from the filtered text.
 */
function hook_filter_secure_image_alter(&$image) {
  // Turn an invalid image into an error indicator.
38
  $image->setAttribute('src', base_path() . 'core/misc/icons/e32700/error.svg');
39 40 41 42 43 44 45 46 47
  $image->setAttribute('alt', t('Image removed.'));
  $image->setAttribute('title', t('This image has been removed. For security reasons, only images from the local domain are allowed.'));

  // Add a CSS class to aid in styling.
  $class = ($image->getAttribute('class') ? trim($image->getAttribute('class')) . ' ' : '');
  $class .= 'filter-image-invalid';
  $image->setAttribute('class', $class);
}

48
/**
49
 * Perform actions when a text format has been disabled.
50 51
 *
 * @param $format
52
 *   The format object of the format being disabled.
53
 */
54 55
function hook_filter_format_disable($format) {
  mymodule_cache_rebuild();
56 57
}

58 59 60
/**
 * @} End of "addtogroup hooks".
 */