function hook_background_image_build_alter in Background Image 2.x
Same name and namespace in other branches
- 8 background_image.api.php \hook_background_image_build_alter()
- 2.0.x background_image.api.php \hook_background_image_build_alter()
Provides extensions a way to alter the image after its been built.
Parameters
array $element: The background image 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.
1 invocation of hook_background_image_build_alter()
- BackgroundImageViewBuilder::buildImage in src/
BackgroundImageViewBuilder.php - Builds the image render array.
File
- ./
background_image.api.php, line 51 - API hooks and alters for the background_image module.
Code
function hook_background_image_build_alter(array &$element, array &$context) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $context['entity'];
// Add some custom field to float over the image.
if ($entity && $entity
->hasField('field_custom_field') && ($custom_field = $entity
->get('field_custom_field')
->view())) {
$element['custom_field'] = $custom_field;
}
}