lory-8.x-1.x-dev/lory.module

lory.module
<?php

/**
 * @file
 * Provides Lory integration, a touch enabled minimalistic slider.
 */

use Drupal\blazy\Blazy;
use Drupal\lory\LoryDefault;

/**
 * Provides a convenient shortcut for procedural hooks.
 *
 * @param string $key
 *   Identifier of the service.
 *
 * @return class
 *   The required Lory class instance.
 */
function lory($key = 'manager') {
  static $manager;
  static $asset_manager;

  if (!isset($manager)) {
    $manager = \Drupal::service('lory.manager');
    $asset_manager = \Drupal::service('lory.asset_manager');
  }

  switch ($key) {
    case 'asset':
      return $asset_manager;

    default:
      return $manager;
  }
}

/**
 * Implements hook_theme().
 */
function lory_theme() {
  $themes = [];
  foreach (['lory', 'lory_wrapper'] as $item) {
    $themes[$item] = [
      'render element' => 'element',
      'file' => 'lory.theme.inc',
    ];
  }
  return $themes;
}

/**
 * Implements hook_library_info_build().
 */
function lory_library_info_build() {
  return lory('asset')->libraryInfoBuild();
}

/**
 * Implements hook_config_schema_info_alter().
 */
function lory_config_schema_info_alter(array &$definitions) {
  Blazy::configSchemaInfoAlter($definitions, 'lory_base', LoryDefault::extendedSettings());
}

/**
 * Implements hook_library_info_alter().
 */
function lory_library_info_alter(&$libraries, $extension) {
  if ($extension === 'lory' && $path = lory_libraries_get_path('lory')) {
    $libraries['lory']['js'] = ['/' . $path . '/dist/lory.min.js' => ['weight' => -4]];
  }
}

/**
 * Provides a wrapper to replace deprecated libraries_get_path() at ease.
 *
 * @todo remove and replace with blazy_libraries_get_path() post blazy:8.x-2.0.
 */
function lory_libraries_get_path($name, $base_path = FALSE) {
  if (function_exists('blazy_libraries_get_path')) {
    return blazy_libraries_get_path($name, $base_path);
  }
  if (\Drupal::hasService('library.libraries_directory_file_finder')) {
    return \Drupal::service('library.libraries_directory_file_finder')->find($name);
  }

  $function = 'libraries_get_path';
  return is_callable($function) ? $function($name, $base_path) : FALSE;
}

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

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