function hook_background_image_text_after_build_alter in Background Image 8
Same name and namespace in other branches
- 2.x background_image.api.php \hook_background_image_text_after_build_alter()
- 2.0.x background_image.api.php \hook_background_image_text_after_build_alter()
Provides extensions a way to alter the text after it's been tokenized.
Parameters
array $element: The text render array element.
array $context: An associative array containing:
- background_image: \Drupal\background_image\BackgroundImageInterface The current Background Image entity being processed.
- entity: \Drupal\Core\Entity\EntityInterface The entity determined to be associated with the background image. Note: this may not be set.
- token_data: The token data to use for any token replacements.
- token_options: The token options to use for any token replacements.
1 invocation of hook_background_image_text_after_build_alter()
- BackgroundImageViewBuilder::buildText in src/
BackgroundImageViewBuilder.php - Builds the text render array.
File
- ./
background_image.api.php, line 103 - API hooks and alters for the background_image module.
Code
function hook_background_image_text_after_build_alter(array &$element, array &$context) {
// Remove any empty tags that may exist due to tokens not matching.
$element['#text'] = preg_replace('/(?:\\n|\\s*)?<([^>\\s]+)[^>]*>(?:(?:<br\\s*\\/?>| | | | | | | |\\n|\\r|\\s)*)*<\\/\\1>(?:\\n|\\s*)?/mi', '', $element['#text']);
}