You are here

isotope.module in Isotope (with Masonry and Packery) 8

Same filename and directory in other branches
  1. 6 isotope.module
  2. 7.2 isotope.module
  3. 7 isotope.module

Isotope module.

File

isotope.module
View source
<?php

/**
 * @file
 * Isotope module.
 */

/**
 * Implements hook_theme().
 */
function isotope_theme() {
  return [
    'isotope_grid' => [
      'variables' => [
        'presentation' => 'default',
        'items' => [],
        'instance' => NULL,
      ],
      'file' => 'isotope.theme.inc',
    ],
    'isotope_filter' => [
      'variables' => [
        'items' => [],
        'instance' => NULL,
        'filter_name' => 'filter',
        'filter_title' => NULL,
        'default_label' => NULL,
      ],
      'file' => 'isotope.theme.inc',
    ],
    'isotope_filter_button' => [
      'variables' => [
        'value' => NULL,
        'label' => NULL,
      ],
      'file' => 'isotope.theme.inc',
    ],
    'isotope_sorter' => [
      'variables' => [
        'sorts' => [],
        'default_label' => NULL,
        'instance' => NULL,
      ],
      'file' => 'isotope.theme.inc',
    ],
    'isotope_sorter_button' => [
      'variables' => [
        'value' => NULL,
        'label' => NULL,
      ],
      'file' => 'isotope.theme.inc',
    ],
  ];
}

/**
 * Implements hook_library_info_alter().
 */
function isotope_library_info_alter(&$libraries, $extension) {

  // Optionally use the Libraries module to determine our library paths.
  if ($extension == 'isotope' && \Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    $search_for = [
      'imagesloaded' => 'imagesloaded.pkgd.min.js',
      'isotope-cells-by-column' => 'cells-by-column.js',
      'isotope-cells-by-row' => 'cells-by-row.js',
      'isotope-fit-columns' => 'fit-columns.js',
      'isotope-horizontal' => 'horizontal.js',
      'isotope-layout' => 'isotope.pkgd.min.js',
      'isotope-masonry-horizontal' => 'masonry-horizontal.js',
      'packery' => 'packery.pkgd.min.js',
    ];
    foreach ($search_for as $lib_name => $lib_file) {

      // $discovery = new \Drupal\libraries\ExternalLibrary\Definition\ChainDefinitionDiscovery();
      // try {
      //   $lib = $discovery->getDefinition($lib_name);
      // }
      // catch (Drupal\libraries\ExternalLibrary\Exception\LibraryDefinitionNotFoundException $e) {}
      // @TODO: libraries_get_path() is deprecated. Waiting for best practice to emerge as libraries module matures.
      $local_file = libraries_get_path($lib_name) . '/' . $lib_file;
      if (file_exists($local_file)) {
        $file_description = preg_match('/\\.min\\./', $local_file) ? [
          'minified' => 'true',
        ] : [];
        $libraries[$lib_name]['js'] = [
          '/' . $local_file => $file_description,
        ];
      }
    }
  }
}

Functions