You are here

flipbook.module in 3D Flipbook 8

Contains flipbook.module.

File

flipbook.module
View source
<?php

/**
 * @file
 * Contains flipbook.module.
 */
use Drupal\file\Entity\File;

/**
 * Implements hook_preprocess_page().
 */
function flip_preprocess_page(&$variables) {
  $config = \Drupal::config('config.flipbook_chooseconfig');
  $choice_value = $config
    ->get('pdf.choice');
  global $base_url;
  $host = $base_url;
  $object = $variables['element']['#object'];
  $typeLabel = $object
    ->get('name')
    ->getValue();
  $flipbook = $object
    ->get('flipbook')
    ->getValue();
  $flipdata = $flipbook[0]['target_id'];
  $file1 = File::load($flipdata);
  $url = file_create_url($file1
    ->getFileUri());
  $variables['#attached']['drupalSettings']['pdfpath'][$flipdata] = $url;
  $flipimage = $object
    ->get('flipbook_cover')
    ->getValue()[0]['target_id'];
  $file = File::load($flipimage);
  $coverimageurl = file_create_url($file
    ->getFileUri());
  if ($choice_value == 1) {
    $variables['#attached']['library'][] = 'flipbook/flipbook';
  }
  else {
    $variables['#attached']['library'][] = 'flipbook/flipbook_nopopup';
  }
  $variables['#attached']['drupalSettings']['modulepath'] = drupal_get_path('module', 'flipbook');
  $variables['#attached']['drupalSettings']['pdfpath'] = $url;
  $variables['#attached']['drupalSettings']['pdfchoice'] = $choice_value;
  $variables['#attached']['drupalSettings']['host'] = $host;
  $variables['title'] = $typeLabel[0]['value'];
  $variables['bannercover'] = $coverimageurl;
  $variables['url'] = $url;
  $variables['pdfchoice'] = $choice_value;
}

/**
 * Implements hook_theme_registry_alter().
 */
function flipbook_theme_registry_alter(&$theme_registry) {
  $theme_registry['field__flipbook__flipbook__flipbook']['path'] = drupal_get_path('module', 'flipbook') . '/templates';
  $theme_registry['field__flipbook__flipbook__flipbook']['template'] = 'flipbook';
  $theme_registry['field__flipbook__flipbook__flipbook']['preprocess functions'] = [
    0 => 'flip_preprocess_page',
  ];
  $theme_registry['views_view_field__field_flipbook']['path'] = drupal_get_path('module', 'flipbook') . '/templates/';
  $theme_registry['views_view_field__field_flipbook']['template'] = 'flipbook';
  $theme_registry['views_view_field__field_flipbook']['preprocess functions'] = [
    0 => 'flip_preprocess_page',
  ];
}

Functions

Namesort descending Description
flipbook_theme_registry_alter Implements hook_theme_registry_alter().
flip_preprocess_page Implements hook_preprocess_page().