function hook_filter_secure_image_alter
Same name in other branches
- 9 core/modules/filter/filter.api.php \hook_filter_secure_image_alter()
- 8.9.x core/modules/filter/filter.api.php \hook_filter_secure_image_alter()
- 11.x core/modules/filter/filter.api.php \hook_filter_secure_image_alter()
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.
Parameters
DOMElement $image: An IMG node to format, parsed from the filtered text.
Related topics
1 function implements hook_filter_secure_image_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- filter_filter_secure_image_alter in core/
modules/ filter/ filter.module - Implements hook_filter_secure_image_alter().
1 invocation of hook_filter_secure_image_alter()
- _filter_html_image_secure_process in core/
modules/ filter/ filter.module - Process callback for local image filter.
File
-
core/
modules/ filter/ filter.api.php, line 36
Code
function hook_filter_secure_image_alter(&$image) {
// Turn an invalid image into an error indicator.
$image->setAttribute('src', base_path() . 'core/misc/icons/e32700/error.svg');
$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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.