function filter_filter_secure_image_alter

filter_filter_secure_image_alter(&$image)

Implements hook_filter_secure_image_alter().

Formats an image DOM element that has an invalid source.

Parameters

DOMElement $image: An IMG node to format, parsed from the filtered text.

See also

_filter_html_image_secure_process()

Related topics

Standard filters
Filters implemented by the Filter module.

File

core/modules/filter/filter.module, line 813
Framework for handling the filtering of content.

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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!filter!filter.module/function/filter_filter_secure_image_alter/8.1.x