You are here

nice_imagefield_widget.module in Nice ImageField Widget 7

Same filename and directory in other branches
  1. 8 nice_imagefield_widget.module
  2. 7.2 nice_imagefield_widget.module

File

nice_imagefield_widget.module
View source
<?php

/**
 * @file
 * Module implementing Nice ImageField Widget.
 */
module_load_include('inc', 'nice_imagefield_widget', 'nice_imagefield_widget.field');

/**
 * Implements hook_requirements().
 *
 * @param $phase
 * @return array
 */
function nice_imagefield_widget_requirements($phase) {

  // Create an array to hold Nice ImageField Widget requirements.
  $requirements = array();

  // Check requirements during the runtime phase.
  if ($phase == 'runtime') {

    // Check if the jQuery Flip plugin library is installed.
    if (($library = libraries_detect('flip')) && !empty($library['installed'])) {
      $requirements['nice_imagefield_widget_library'] = array(
        'title' => t('jQuery Flip plugin'),
        'value' => t('Installed'),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['nice_imagefield_widget_library'] = array(
        'title' => t('jQuery Flip plugin'),
        'value' => t('Not installed'),
        'description' => t('<em>Nice ImageField Widget</em> module requires <a href="@jquery_flip">jQuery Flip</a> plugin.', array(
          '@jquery_flip' => $library['vendor url'],
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_libraries_info().
 */
function nice_imagefield_widget_libraries_info() {
  $libraries['flip'] = array(
    'name' => 'jQuery Flip',
    'vendor url' => 'http://nnattawat.github.io/flip/',
    'download url' => 'https://github.com/nnattawat/flip',
    'version arguments' => array(
      'file' => 'dist/jquery.flip.min.js',
      // flip v1.0.0
      'pattern' => '/flip - v(\\d+\\.+\\d+)/',
      'lines' => 1,
    ),
    'files' => array(
      'js' => array(
        'dist/jquery.flip.min.js',
      ),
    ),
    'integration files' => array(
      'nice_imagefield_widget' => array(
        'js' => array(
          'js/nice_imagefield_widget.js',
        ),
        'css' => array(
          'css/nice_imagefield_widget.css',
        ),
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_library().
 */
function nice_imagefield_widget_library() {
  $module_path = drupal_get_path('module', 'nice_imagefield_widget');
  $library_path = libraries_get_path('flip');
  $libraries['flip'] = array(
    'title' => 'jQuery Flip',
    'website' => 'http://nnattawat.github.io/flip/',
    'version' => '1.0',
    'js' => array(
      $library_path . '/dist/jquery.flip.min.js' => array(),
      $module_path . '/js/nice_imagefield_widget.js' => array(),
    ),
    'css' => array(
      $module_path . '/css/nice_imagefield_widget.css' => array(
        'type' => 'file',
        'media' => 'screen',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_theme().
 */
function nice_imagefield_widget_theme() {
  $default = array(
    'render element' => 'element',
    'file' => 'nice_imagefield_widget.theme.inc',
  );
  return array(
    'nice_imagefield_widget_multiple' => $default,
    'nice_imagefield_widget_image' => $default,
  );
}

/**
 * Implements hook_image_default_styles().
 */
function nice_imagefield_widget_image_default_styles() {
  return array(
    'nice_image' => array(
      'label' => 'Nice Image (288x180)',
      'effects' => array(
        array(
          'name' => 'image_scale_and_crop',
          'data' => array(
            'width' => 288,
            'height' => 180,
          ),
        ),
      ),
    ),
  );
}