You are here

gridstack.module in GridStack 8.2

Same filename and directory in other branches
  1. 8 gridstack.module

Provides GridStack integration to have multi-column grids with drag-and-drop.

File

gridstack.module
View source
<?php

/**
 * @file
 * Provides GridStack integration to have multi-column grids with drag-and-drop.
 */

/**
 * Provides a convenient shortcut for procedural hooks.
 *
 * @return class
 *   The GridStack class instances.
 */
function gridstack($key = 'manager') {
  static $hook;
  static $manager;
  if (!isset($manager)) {
    $hook = \Drupal::service('gridstack.hook');
    $manager = \Drupal::service('gridstack.manager');
  }
  switch ($key) {
    case 'hook':
      return $hook;
    case 'engine':
      return $manager
        ->engineManager();
    case 'skin':
      return $manager
        ->skinManager();
    case 'style':
      return $manager
        ->stylizer();
    default:
      return $manager;
  }
}

/**
 * Implements hook_theme().
 */
function gridstack_theme() {
  $themes = [];
  foreach ([
    'gridstack',
    'box',
  ] as $item) {
    $key = $item == 'gridstack' ? $item : 'gridstack_' . $item;
    $themes[$key] = [
      'render element' => 'element',
      'file' => 'templates/gridstack.theme.inc',
    ];
  }
  return $themes;
}

/**
 * Implements hook_library_info_build().
 */
function gridstack_library_info_build() {
  return gridstack('skin')
    ->libraryInfoBuild();
}

/**
 * Implements hook_library_info_alter().
 */
function gridstack_library_info_alter(&$libraries, $extension) {
  if ($extension === 'gridstack') {
    gridstack('hook')
      ->libraryInfoAlter($libraries, $extension);
  }
}

/**
 * Implements hook_field_formatter_info_alter().
 */
function gridstack_field_formatter_info_alter(array &$info) {
  gridstack('hook')
    ->fieldFormatterInfoAlter($info);
}

/**
 * Implements hook_layout_alter().
 */
function gridstack_layout_alter(&$definitions) {
  gridstack('hook')
    ->layoutAlter($definitions);
}

/**
 * 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 gridstack_libraries_get_path($name, $base_path = FALSE) {
  return function_exists('blazy_libraries_get_path') ? blazy_libraries_get_path($name, $base_path) : FALSE;
}

/**
 * Overrides template_preprocess_blazy().
 */
function gridstack_preprocess_blazy(array &$variables) {
  $settings =& $variables['settings'];

  // Aspect ratio doesn't work out well with various box sizes, disable.
  if (isset($settings['view_plugin_id']) && $settings['view_plugin_id'] == 'gridstack') {
    $variables['attributes']['class'][] = 'b-noratio';
  }
}

/**
 * Implements hook_config_schema_info_alter().
 */
function gridstack_config_schema_info_alter(array &$definitions) {
  if (isset($definitions['gridstack_vanilla']) || isset($definitions['layout_plugin.settings']) || isset($definitions['core.entity_view_display.*.*.*.third_party.ds'])) {
    gridstack('hook')
      ->configSchemaInfoAlter($definitions);
  }
}