You are here

function parallax_bg_page_attachments in Parallax Background 8

Implements hook_page_attachments().

File

./parallax_bg.module, line 29
Contains parallax_bg.module.

Code

function parallax_bg_page_attachments(array &$attachments) {
  $settings = [];

  /** @var \Drupal\parallax_bg\Entity\ParallaxElementInterface[] $elements */
  $elements = \Drupal::entityTypeManager()
    ->getStorage('parallax_element')
    ->loadMultiple();
  foreach ($elements as $element) {
    $settings[] = [
      'selector' => $element
        ->getSelector(),
      'position' => $element
        ->getPosition(),
      'speed' => $element
        ->getSpeed(),
    ];
  }
  if (!empty($settings)) {
    $attachments['#attached']['library'][] = 'parallax_bg/parallax_bg';
    $attachments['#attached']['drupalSettings']['parallax_bg'] = $settings;
  }
}