You are here

image_desaturate_formatter.module in Image desaturate formatter 8

Code for the Image desaturate formatter module.

File

image_desaturate_formatter.module
View source
<?php

/**
 * @file
 * Code for the Image desaturate formatter module.
 */

/**
 * Implements hook_theme().
 */
function image_desaturate_formatter_theme() {
  return array(
    'image_desaturate_formatter' => array(
      'variables' => array(
        'item' => NULL,
        'image_style' => NULL,
        'path' => NULL,
        'default_style' => 'desaturate',
      ),
    ),
  );
}

/**
 * Returns HTML for an image_desaturate field formatter.
 *
 * @param array $variables
 *   An associative array containing:
 *   - item: An array of image data.
 *   - image_style: An optional image style.
 *   - path: An optional array containing the link 'path' and link 'options'.
 *   - default_style: An optional image color style
 *
 * @ingroup themeable
 */
function theme_image_desaturate_formatter($variables) {
  $variables['item']['attributes'] = array(
    'class' => array(
      $variables['default_style'] == 'desaturate' ? 'desaturate-formatter' : 'no-desaturate-formatter',
    ),
  );
  $render = array(
    '#theme' => 'image_formatter',
    '#item' => $variables['item'],
    '#image_style' => $variables['image_style'],
    '#path' => $variables['path'],
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'image_desaturate_formatter') . '/library/image_desaturate_formatter.css',
      ),
    ),
  );
  return drupal_render($render);
}

/**
 * Implements hook_library_info().
 */
function image_desaturate_formatter_library_info() {
  $libraries['image-desaturate-formatter'] = array(
    'title' => 'Image desaturate Formatter',
    'version' => '1',
    'css' => array(
      drupal_get_path('module', 'image_desaturate_formatter') . '/library/image_desaturate_formatter.css' => array(),
    ),
  );
  return $libraries;
}

Functions

Namesort descending Description
image_desaturate_formatter_library_info Implements hook_library_info().
image_desaturate_formatter_theme Implements hook_theme().
theme_image_desaturate_formatter Returns HTML for an image_desaturate field formatter.