skinr-8.x-2.0-alpha2/tests/modules/skinr_test/skinr_test.module

tests/modules/skinr_test/skinr_test.module
<?php

/**
 * @file
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
 * @file
 * Skinr testing module.
 *
 * Other modules should be able to place their Skinr support/integration code
 * into a conditionally loaded $module.skinr.inc file, so this .module file
 * only exists, because Drupal requires a .module file to exist.
 */

/**
 * Implements hook_menu().
 */
function skinr_test_menu() {
  $items['skinr-test/current-theme-default'] = [
    'title' => 'Test skinr_current_theme()',
    'page callback' => 'skinr_test_skinr_current_theme',
    'access arguments' => ['access content'],
  ];
  $items['skinr-test/current-theme-callback'] = [
    'title' => 'Test skinr_current_theme() with \'theme callback\'',
    'page callback' => 'skinr_test_skinr_current_theme',
    'access arguments' => ['access content'],
    'theme callback' => 'skinr_test_skinr_current_theme_callback',
  ];
  $items['skinr-test/current-theme-hook-custom-theme'] = [
    'title' => 'Test skinr_current_theme() with hook_custom_theme()',
    'page callback' => 'skinr_test_skinr_current_theme',
    'access arguments' => ['access content'],
  ];
  $items['admin/skinr-test/current-theme-admin'] = [
    'title' => 'Test skinr_current_theme() for admin theme',
    'page callback' => 'skinr_test_skinr_current_theme',
    'access arguments' => ['access content'],
  ];
  $items['admin/skinr-test/current-theme-admin-exclude'] = [
    'title' => 'Test skinr_current_theme() excluding admin theme',
    'page callback' => 'skinr_test_skinr_current_theme_admin_exclude',
    'access arguments' => ['access content'],
  ];
  $items['skinr-test/hook-dynamic-loading'] = [
    'title' => 'Test hook dynamic loading (skinr_hook)',
    'page callback' => 'skinr_test_hook_dynamic_loading',
    'access arguments' => ['access content'],
  ];
  $items['skinr-test/skinr-implements-api'] = [
    'title' => 'Test skinr_implements_api()',
    'page callback' => 'skinr_test_skinr_implements_api',
    'access arguments' => ['access content'],
  ];
  return $items;
}

/**
 * Page callback for default 'skinr_current_theme' test.
 *
 * Displays the current theme.
 */
function skinr_test_skinr_current_theme() {
  return 'Current theme is ' . skinr_current_theme() . '.';
}

/**
 * Theme callback for skinr-test/current-theme-hook-custom-theme.
 */
function skinr_test_skinr_current_theme_callback() {
  return 'garland';
}

/**
 * Implements hook_custom_theme().
 */
function skinr_test_custom_theme() {
  if (Url::fromRoute("<current>")->toString() == 'skinr-test/current-theme-hook-custom-theme') {
    return 'garland';
  }
}

/**
 * Page callback for 'skinr_current_theme' test.
 *
 * Displays the current theme.
 */
function skinr_test_skinr_current_theme_admin_exclude() {
  return 'Current theme is ' . skinr_current_theme(TRUE) . '.';
}

/**
 * Page callback for 'hook dynamic loading' test.
 *
 * If the hook is dynamically loaded correctly, the menu callback should
 * return 'success!'.
 */
function skinr_test_hook_dynamic_loading() {
  if (skinr_hook('skinr_test', 'skinr_group_info') && function_exists('skinr_test_skinr_group_info')) {
    return 'success!';
  }
  return 'failed!';
}

/**
 * Page callback for 'skinr_implements_api' test.
 *
 * If the hook is dynamically loaded correctly, the menu callback should
 * return a list of extensions.
 */
function skinr_test_skinr_implements_api() {
  $extensions = skinr_implements_api();
  $output = '';
  foreach ($extensions as $extension_name => $extension) {
    $output .= $extension_name . '<br />';
  }
  return $output;
}

/**
 * Implements hook_system_theme_info().
 *
 * @see http://drupal.org/node/953336
 */
function skinr_test_system_theme_info() {
  $path = \Drupal::service('extension.path.resolver')->getPath('module', 'skinr_test');
  $test_themes = ['basetheme', 'subtheme', 'basetheme_other', 'subtheme_other'];
  foreach ($test_themes as $theme) {
    $themes["skinr_test_{$theme}"] = $path . "/themes/skinr_test_{$theme}/skinr_test_{$theme}.info";
  }
  return $themes;
}

//
// Presave hooks
// .

/**
 * Implements hook_skinr_skin_presave().
 */
function skinr_test_skinr_skin_presave() {
  $_SESSION['skinr_test'][] = (__FUNCTION__ . ' called');
}

//
// Insert hooks
// .

/**
 * Implements hook_skinr_skin_insert().
 */
function skinr_test_skinr_skin_insert() {
  $_SESSION['skinr_test'][] = (__FUNCTION__ . ' called');
}

//
// Load hooks
// .

/**
 * Implements hook_entity_load().
 */
function skinr_test_entity_load(array $entities, $entity_type_id) {
  if ($entity_type_id !== 'skin') {
    return;
  }
  $_SESSION['skinr_test'][] = (__FUNCTION__ . ' called');
}

//
// Update hooks
// .

/**
 * Implements hook_skinr_skin_update().
 */
function skinr_test_skinr_skin_update() {
  $_SESSION['skinr_test'][] = (__FUNCTION__ . ' called');
}

//
// Delete hooks
// .

/**
 * Implements hook_entity_delete().
 */
function skinr_test_entity_delete(EntityInterface $entity) {
  if ($entity->getEntityTypeId() !== 'skin') {
    return;
  }
  $_SESSION['skinr_test'][] = (__FUNCTION__ . ' called');
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc