function filter_filter_secure_image_alter

Same name in other branches
  1. 9 core/modules/filter/filter.module \filter_filter_secure_image_alter()
  2. 8.9.x core/modules/filter/filter.module \filter_filter_secure_image_alter()
  3. 11.x core/modules/filter/filter.module \filter_filter_secure_image_alter()

Implements hook_filter_secure_image_alter().

Formats an image DOM element that has an invalid source.

See also

_filter_html_image_secure_process()

Related topics

File

core/modules/filter/filter.module, line 847

Code

function filter_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.'));
    $image->setAttribute('height', '16');
    $image->setAttribute('width', '16');
    // 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.