You are here

variable_example.module in Variable 7

Same filename and directory in other branches
  1. 7.2 variable_example/variable_example.module

File

variable_example/variable_example.module
View source
<?php

/**
 * Variable example.
 */

/**
 * Implements hook_menu().
 */
function variable_example_menu() {
  $items['admin/config/system/variable_example'] = array(
    'title' => 'Variable example',
    'description' => 'Example of auto generated settings form.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'variable_group_form',
      'variable_example',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  $items['variable/example'] = array(
    'title' => 'Variable example',
    'description' => 'List some variables.',
    'page callback' => 'variable_example_page_list',
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  $items['variable/realm/%/%'] = array(
    'title' => 'Variable example realm',
    'description' => 'Example of variable realms.',
    'page callback' => 'variable_example_page_realm',
    'page arguments' => array(
      2,
      3,
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  return $items;
}

/**
 * Variable example realm page.
 *
 * Will switch to given realm and display variables.
 */
function variable_example_page_list() {
  variable_include();
  $list = variable_list_group('site_information') + variable_list_group('variable_example');
  foreach ($list as $name => $variable) {
    $build[$name] = array(
      '#type' => 'item',
      '#title' => $variable['title'],
      '#markup' => variable_format_value($variable),
    );
  }
  return $build;
}

/**
 * Variable example realm page.
 *
 * Will switch to given realm and display variables.
 */
function variable_example_page_realm($realm, $key) {

  // Initialize realm from variable store.
  $variables = variable_store($realm, $key);

  // Set at least one variable for the realm
  $variables += array(
    'site_name' => 'Variable example realm',
  );
  variable_realm_add($realm, $key, $variables);
  variable_realm_switch($realm, $key);
  return variable_example_page_list();
}

Functions

Namesort descending Description
variable_example_menu Implements hook_menu().
variable_example_page_list Variable example realm page.
variable_example_page_realm Variable example realm page.