You are here

parallax_bg.module in Parallax Background 8

Same filename and directory in other branches
  1. 7 parallax_bg.module

Contains parallax_bg.module.

File

parallax_bg.module
View source
<?php

/**
 * @file
 * Contains parallax_bg.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function parallax_bg_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the parallax_bg module.
    case 'help.page.parallax_bg':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Create a Parallax Background effect on any tagged element.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_page_attachments().
 */
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;
  }
}

Functions