You are here

function hook_background_image_build_alter in Background Image 8

Same name and namespace in other branches
  1. 2.x background_image.api.php \hook_background_image_build_alter()
  2. 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:

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