filter.api.php

  1. 7.x drupal/modules/filter/filter.api.php
  2. 8.x drupal/core/modules/filter/filter.api.php

Hooks provided by the Filter module.

Functions

Namesort descending Description
hook_filter_format_disable Perform actions when a text format has been disabled.
hook_filter_info_alter Perform alterations on filter definitions.
hook_filter_secure_image_alter Alters images with an invalid source.

File

drupal/core/modules/filter/filter.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Filter module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Perform alterations on filter definitions.
  12. *
  13. * @param $info
  14. * Array of information on filters exposed by filter plugins.
  15. */
  16. function hook_filter_info_alter(&$info) {
  17. // Alter the default settings of the URL filter provided by core.
  18. $info['filter_url']['default_settings'] = array(
  19. 'filter_url_length' => 100,
  20. );
  21. }
  22. /**
  23. * Alters images with an invalid source.
  24. *
  25. * When the 'Restrict images to this site' filter is enabled, any images that
  26. * are not hosted on the site will be passed through this hook, most commonly to
  27. * replace the invalid image with an error indicator.
  28. *
  29. * @param DOMElement $image
  30. * An IMG node to format, parsed from the filtered text.
  31. */
  32. function hook_filter_secure_image_alter(&$image) {
  33. // Turn an invalid image into an error indicator.
  34. $image->setAttribute('src', base_path() . 'core/misc/message-16-error.png');
  35. $image->setAttribute('alt', t('Image removed.'));
  36. $image->setAttribute('title', t('This image has been removed. For security reasons, only images from the local domain are allowed.'));
  37. // Add a CSS class to aid in styling.
  38. $class = ($image->getAttribute('class') ? trim($image->getAttribute('class')) . ' ' : '');
  39. $class .= 'filter-image-invalid';
  40. $image->setAttribute('class', $class);
  41. }
  42. /**
  43. * Perform actions when a text format has been disabled.
  44. *
  45. * @param $format
  46. * The format object of the format being disabled.
  47. */
  48. function hook_filter_format_disable($format) {
  49. mymodule_cache_rebuild();
  50. }
  51. /**
  52. * @} End of "addtogroup hooks".
  53. */