You are here

salvattore.module in Salvattore (CSS driven Masonry) 8

Same filename and directory in other branches
  1. 7.2 salvattore.module
  2. 7 salvattore.module

Salvattore masonry plugin for views.

File

salvattore.module
View source
<?php

/**
 * @file
 * Salvattore masonry plugin for views.
 */

// Regular expression to determine which version of Salvattore is installed.
define('SALVATTORE_VERSION_REGEX', '/(1\\.\\d\\.\\d)/');

/**
 * Implements hook_permission().
 */
function salvattore_permission() {
  return array(
    'manage Salvattore settings' => array(
      'title' => t('Manage Salvattore settings'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function salvattore_menu() {
  $items = array();
  $items['admin/config/user-interface/salvattore'] = array(
    'title' => 'Salvattore Settings',
    'description' => 'Configure Salvattore',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'salvattore_admin_settings_form',
    ),
    'access arguments' => array(
      'manage Salvattore settings',
    ),
    'file' => 'salvattore.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_views_api()
 */
function salvattore_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Preprocess function for views_view_salvattore.tpl.php.
 */
function template_preprocess_views_view_salvattore(&$vars) {

  // Run preprocess function for unformatted style
  template_preprocess_views_view_unformatted($vars);

  // Get view options
  $view = $vars['view'];
  $options = $vars['options'];
}

/**
 * Implements template_preprocess_views_view().
 */
function salvattore_preprocess_views_view_salvattore(&$vars) {

  // @FIXME
  // The Assets API has totally changed. CSS, JavaScript, and libraries are now
  // attached directly to render arrays using the #attached property.
  //
  //
  // @see https://www.drupal.org/node/2169605
  // @see https://www.drupal.org/node/2408597
  // drupal_add_js(salvattore_get_path(), array('scope' => 'footer'));
  // @FIXME
  // Could not extract the default value because it is either indeterminate, or
  // not scalar. You'll need to provide a default value in
  // config/install/salvattore.settings.yml and config/schema/salvattore.schema.yml.
  if (\Drupal::config('salvattore.settings')
    ->get('salvattore_load_default_css')) {

    // @FIXME
    // The Assets API has totally changed. CSS, JavaScript, and libraries are now
    // attached directly to render arrays using the #attached property.
    //
    //
    // @see https://www.drupal.org/node/2169605
    // @see https://www.drupal.org/node/2408597
    // drupal_add_css(drupal_get_path('module', 'salvattore') . '/css/salvattore_default.css', array(
    //       'type' => 'file',
    //       'preprocess' => FALSE, // see README
    //     ));
  }
}

/**
 * 
 */
function salvattore_get_path() {
  $salvattore_path = libraries_get_path('salvattore');

  // @FIXME
  // Could not extract the default value because it is either indeterminate, or
  // not scalar. You'll need to provide a default value in
  // config/install/salvattore.settings.yml and config/schema/salvattore.schema.yml.
  if (\Drupal::config('salvattore.settings')
    ->get('salvattore_use_min_js')) {
    $salvattore_path .= '/dist/salvattore.min.js';
  }
  else {
    $salvattore_path .= '/dist/salvattore.js';
  }
  return $salvattore_path;
}

/**
 * Guesses the salvattore library version.
 *
 * This function is using a regex, which assumes that the format of the version
 * string won't change. If it changes, feel free to submit a bug report.
 *
 * @return mixed The version number if exists, or a boolean FALSE if it can't be
 * determined.
 */
function salvattore_get_version($reset = FALSE) {
  $version =& drupal_static(__FUNCTION__);
  if ($version === NULL || $reset == TRUE) {
    if ($cached = \Drupal::cache()
      ->get('salvattore_version') && isset($cached->data) && $reset != TRUE) {
      $version = $cached->data;
    }
    else {
      $version = FALSE;
      $salvattore_path = salvattore_get_path();
      if (file_exists($salvattore_path)) {
        $salvattore = file_get_contents($salvattore_path);
        $matches = array();
        preg_match(SALVATTORE_VERSION_REGEX, $salvattore, $matches);
        if (isset($matches[0])) {
          $version = $matches[0];
          if ($version) {
            \Drupal::cache()
              ->set('salvattore_version', $version);
          }
        }
        unset($salvattore);
      }
    }
  }
  return $version;
}

Functions

Namesort descending Description
salvattore_get_path
salvattore_get_version Guesses the salvattore library version.
salvattore_menu Implements hook_menu().
salvattore_permission Implements hook_permission().
salvattore_preprocess_views_view_salvattore Implements template_preprocess_views_view().
salvattore_views_api Implements hook_views_api()
template_preprocess_views_view_salvattore Preprocess function for views_view_salvattore.tpl.php.

Constants