You are here

function hook_juicebox_gallery_alter in Juicebox HTML5 Responsive Image Galleries 8.2

Same name and namespace in other branches
  1. 8.3 juicebox.api.php \hook_juicebox_gallery_alter()
  2. 7.2 juicebox.api.php \hook_juicebox_gallery_alter()

Allow modules to alter the Juicebox gallery object.

Juicebox gallery object is used to build gallery embed code and XML before rendering.

Parameters

object $gallery: A Juicebox gallery object that contains the gallery which is going to be rendered. This object can be further manipulated using any methods from Drupal\juicebox\JuiceboxGalleryInterface.

mixed $data: The raw Drupal data that was used to build this gallery. Provided for context.

1 invocation of hook_juicebox_gallery_alter()
JuiceboxFormatter::runCommonBuild in src/JuiceboxFormatter.php
Common post-build task.

File

./juicebox.api.php, line 22
Hooks provided by the Juicebox module.

Code

function hook_juicebox_gallery_alter($gallery, $data) {

  // Only make changes to galleries that use the field formatter.
  if (strpos($gallery
    ->getId(), 'field') === 0) {
    foreach ($gallery
      ->getImages() as $key => $image) {

      // Add some static text to all title values and write changes back.
      $image['title'] .= ' © 2014';
      $gallery
        ->updateImage($key, $image['src_data'], $image['title'], $image['caption']);
    }
  }
}