filter.api.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 array $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'] = [
  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/icons/e32700/error.svg');
  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 \Drupal\filter\FilterFormatInterface $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. */