You are here

isotope_example.module in Isotope (with Masonry and Packery) 7.2

Simple example module.

File

isotope_example/isotope_example.module
View source
<?php

/**
 * @file
 * Simple example module.
 */

/**
 * Page callback.
 *
 * This is an example of using standard theme functions to output your own
 * lists, without using views.
 *
 * @return array
 *   Drupal render array.
 */
function isotope_example_theme_page() {
  $return[] = array(
    '#markup' => t('<p>You can explore this example for yourself at <strong>isotope_example_page()</strong>.</p>'),
  );

  // The label can be anything, including images, etc. Filtering happens on the
  // key.
  $colors = array(
    'blue' => 'Blue',
    'red' => '<span class="thisIsCustomisedLabel">Red</span>',
    'yellow' => 'Yellow',
  );
  $return[] = array(
    '#theme' => 'isotope_filter',
    '#items' => $colors,
    // Optional filtername: unique to distinguish it from the other filters on
    // the page.
    '#filtername' => 'color',
    // Optional filtertitle: displayed as a list title.
    '#filtertitle' => t('Colour'),
  );
  $sizes = array(
    'small' => 'Small',
    'wide' => 'Wide',
    'big' => 'Big',
    'tall' => 'Tall',
  );
  $return[] = array(
    '#theme' => 'isotope_filter',
    '#items' => $sizes,
    '#filtername' => 'size',
    '#filtertitle' => t('Size'),
  );
  $shapes = array(
    'round' => 'Round',
    'square' => 'Square',
  );
  $return[] = array(
    '#theme' => 'isotope_filter',
    '#items' => $shapes,
    '#filtername' => 'shape',
    '#filtertitle' => t('Shapes'),
    '#instance' => 1,
  );
  $sorts = array(
    'Size' => 'size',
    'shape',
    'color',
    array(
      'color',
      'size',
    ),
    'Color then Shape' => array(
      'color',
      'shape',
    ),
  );
  $return[] = array(
    '#theme' => 'isotope_sorter',
    '#sorts' => $sorts,
    '#original' => 'Original',
    '#instance' => 1,
  );

  // Create items of every size shape and color.
  $items = array();
  foreach ($sizes as $size => $label1) {
    foreach ($shapes as $shape => $label2) {
      foreach ($colors as $color => $label3) {
        $items[] = array(
          'value' => '<p>Item</p>',
          'data' => array(
            'size' => $size,
            'shape' => $shape,
            'color' => $color,
          ),
        );
      }
    }
  }
  $return[] = array(
    '#theme' => 'isotope_grid',
    '#items' => $items,
    '#instance' => 1,
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'isotope_example') . '/isotope_example.css',
      ),
    ),
  );
  return $return;
}

/**
 * Implements hook_views_api().
 */
function isotope_example_views_api() {
  return array(
    'api' => 3.0,
  );
}

/**
 * Implements hook_preprocess_views_view().
 */
function isotope_example_preprocess_views_view(&$vars) {
  if ($vars['name'] == 'isotope_example') {
    drupal_add_css(drupal_get_path('module', 'isotope_example') . '/isotope_example.css');
  }
}

/**
 * Implements hook_node_info().
 */
function isotope_example_node_info() {
  return array(
    'isotope_example' => array(
      'name' => t('Isotope Example Node Type'),
      'base' => 'isotope_example',
      'description' => t('This is an example node type with a few fields.'),
      'title_label' => t('Example Title'),
      'locked' => TRUE,
    ),
  );
}

/**
 * Implements hook_menu().
 */
function isotope_example_menu() {
  $items['isotope-example'] = array(
    'title' => 'Isotope Examples',
    'page callback' => 'isotope_example_page',
    'access callback' => TRUE,
  );
  $items['isotope-example/theme-example'] = array(
    'title' => 'Isotope Theme Example',
    'page callback' => 'isotope_example_theme_page',
    'access callback' => TRUE,
  );
  return $items;
}

/**
 * Page callback.
 *
 * @return array
 *   Drupal render array.
 */
function isotope_example_page() {
  $links[] = l(t('Theme Example'), 'isotope-example/theme-example');
  if (module_exists('isotope_views')) {
    $links[] = l(t('Views Example'), 'isotope-example/views-example');
  }
  $return[] = array(
    '#theme' => 'item_list',
    '#items' => $links,
    '#type' => 'ul',
  );
  return $return;
}

Functions

Namesort descending Description
isotope_example_menu Implements hook_menu().
isotope_example_node_info Implements hook_node_info().
isotope_example_page Page callback.
isotope_example_preprocess_views_view Implements hook_preprocess_views_view().
isotope_example_theme_page Page callback.
isotope_example_views_api Implements hook_views_api().