function hook_background_image_text_build_alter in Background Image 2.x
Same name and namespace in other branches
- 8 background_image.api.php \hook_background_image_text_build_alter()
- 2.0.x background_image.api.php \hook_background_image_text_build_alter()
Provides extensions a way to alter the text before 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_build_alter()
- BackgroundImageViewBuilder::buildText in src/
BackgroundImageViewBuilder.php - Builds the text render array.
File
- ./
background_image.api.php, line 76 - API hooks and alters for the background_image module.
Code
function hook_background_image_text_build_alter(array &$element, array &$context) {
/** @var \Drupal\background_image\BackgroundImageInterface $background_image */
$background_image = $context['background_image'];
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $context['entity'];
// Prepend a header to all full viewport background images.
if ($background_image
->getSetting('full_viewport') && $entity && $entity
->hasField('field_header') && ($header = $entity
->get('field_header')->value)) {
$element['#text'] = '<h2>' . $header . '</h2>' . $element['#text'];
}
}