You are here

login_shadowbox.module in Shadowbox 8

Same filename and directory in other branches
  1. 7.4 login_shadowbox/login_shadowbox.module

Allows login form to be displayed in a JavaScript modal media viewer application.

File

login_shadowbox/login_shadowbox.module
View source
<?php

/**
 * @file
 * Allows login form to be displayed in a JavaScript modal media viewer
 * application.
 */

/**
 * Implmentation of hook_permission()
 */
function login_shadowbox_permission() {
  return array(
    'administer shadowbox login' => array(
      'title' => t('Administer shadowbox login'),
      'description' => t('Allows users to change the settings for the Shadowbox Login module'),
    ),
  );
}

/**
 * Implementation of hook_theme()
 */
function login_shadowbox_theme() {
  return array(
    'login_shadowbox_page' => array(
      'template' => 'login-shadowbox-page',
      'variables' => array(
        'title' => '',
        'content' => NULL,
        'js' => '',
        'css' => '',
      ),
    ),
  );
}

/**
 * Implements hook_page_build().
 */
function login_shadowbox_page_build(&$page) {
  $shadowbox_config = \Drupal::config('shadowbox.settings');
  $login_shadowbox_config = \Drupal::config('login_shadowbox.settings');
  $enable = $login_shadowbox_config
    ->get('login_shadowbox_enabled') && $shadowbox_config
    ->get('shadowbox_enabled');
  $path = drupal_get_path('module', 'login_shadowbox');
  if ($enable && arg(0) != 'admin') {
    $page['#attached']['js'][] = $path . '/scripts/login_shadowbox_check.js';
  }
  if (!\Drupal::currentUser()
    ->id() && $enable) {
    $alias_manager = \Drupal::service('path.alias_manager.cached');
    $login_path = $alias_manager
      ->getPathByAlias('user/login');
    $register_path = $alias_manager
      ->getPathByAlias('user/register');
    $password_path = $alias_manager
      ->getPathByAlias('user/password');
    $login_content = url($alias_manager
      ->getPathByAlias('user/login/shadowbox'));
    $register_content = url($alias_manager
      ->getPathByAlias('user/register/shadowbox'));
    $password_content = url($alias_manager
      ->getPathByAlias('user/password/shadowbox'));

    // Shadowbox login settings
    $shadowbox_login_settings = array(
      'login_path' => $login_path,
      'register_path' => $register_path,
      'password_path' => $password_path,
      'login_content' => $login_content,
      'register_content' => $register_content,
      'password_content' => $password_content,
      'login_width' => $login_shadowbox_config
        ->get('login_shadowbox_width'),
      'register_width' => $login_shadowbox_config
        ->get('login_shadowbox_register_width'),
      'password_width' => $login_shadowbox_config
        ->get('login_shadowbox_password_width'),
      'login_height' => $login_shadowbox_config
        ->get('login_shadowbox_height'),
      'register_height' => $login_shadowbox_config
        ->get('login_shadowbox_register_height'),
      'password_height' => $login_shadowbox_config
        ->get('login_shadowbox_password_height'),
      'modal' => $login_shadowbox_config
        ->get('login_shadowbox_modal'),
    );

    // Adding the neccessary javascript and css files needed by shadowbox login.
    $page['#attached']['js'][] = $path . '/scripts/login_shadowbox.js';
    $page['#attached']['js'][] = array(
      'data' => array(
        'shadowboxLogin' => $shadowbox_login_settings,
      ),
      'type' => 'setting',
    );
    $css_path = $login_shadowbox_config
      ->get('login_shadowbox_css');
    $page['#attached']['css'][] = array(
      'data' => $css_path,
      'group' => 'CSS_DEFAULT',
    );
  }
}

Functions

Namesort descending Description
login_shadowbox_page_build Implements hook_page_build().
login_shadowbox_permission Implmentation of hook_permission()
login_shadowbox_theme Implementation of hook_theme()