You are here

function context_context_conditions in Context 6

Same name and namespace in other branches
  1. 6.2 context.core.inc \context_context_conditions()

Implementation of hook_context_conditions().

Allows modules to integrate with context and provide their native objects as options for setting a context definition. The hook should return an array of items keyed on the object "type" (e.g. "node", "user", etc.) with key-value pairs corresponding to a FormAPI element array with some restrictions and additional info.

'#title': Required. The title of the object / form option. '#type': Required. The FormAPI element type to use. Currently only 'select', 'checkboxes', 'radio', and 'textfield' are allowed. '#description': Optional. Help text to be displayed on the form. '#options': Required. A key-value array of options. They key will be stored and passed to context_set_by_condition(), so the integrating module should use a unique (within its namespace) / usable identifier.

File

./context.core.inc, line 46

Code

function context_context_conditions() {
  $items = array();

  // Content Types
  $nodetypes = array();
  foreach (node_get_types() as $type) {
    $nodetypes[$type->type] = t(drupal_ucfirst($type->name));
  }
  $items['node'] = array(
    '#title' => t('Node pages'),
    '#description' => t('Set this context when viewing a node page or using the add/edit form of one of these content types.'),
    '#options' => $nodetypes,
    '#type' => 'checkboxes',
  );

  // User
  $items['user'] = array(
    '#title' => t('User pages'),
    '#description' => t('Set this context when a user with selected role(s) is viewed'),
    '#options' => user_roles(true),
    '#type' => 'checkboxes',
  );

  // Book
  if (module_exists('book')) {
    $options = array();
    foreach (book_get_books() as $book) {
      $options[$book['menu_name']] = $book['title'];
    }
    $items['book'] = array(
      '#title' => t('Book'),
      '#description' => t('Set this context when a node in the selected book is viewed.'),
      '#options' => $options,
      '#type' => 'checkboxes',
    );
  }

  // Sitewide context
  $items['sitewide'] = array(
    '#title' => t('Sitewide context'),
    '#type' => 'radios',
    '#options' => array(
      0 => t('False'),
      1 => t('True'),
    ),
    '#description' => t('Should this context always be set? If <strong>true</strong>, this context will be active across your entire site.'),
  );

  // Path
  $items['path'] = array(
    '#title' => t('Path'),
    '#description' => t('Set this context when any of the paths above match the beginning or all of the page path. Put each path on a separate line.'),
    '#type' => 'textarea',
    '#element_validate' => array(
      'context_condition_text_validate',
    ),
  );
  return $items;
}