You are here

modal_term_view.module in Modal operations 7

Allows taxonomy term viewing in modal window.

@example Create links with the following href and class attributes (TID is the identifier of the term to view): <a href="/modal/taxonomy/term/TID/nojs" class="ctools-use-modal">View term</a>.

Ensure the page with such links executes the following functions (this is done in init code of modal.module): ctools_include('modal'); ctools_modal_add_js();

File

modal_term_view/modal_term_view.module
View source
<?php

/**
 * @file
 * Allows taxonomy term viewing in modal window.
 *
 * @example
 * Create links with the following href and class attributes (TID is the identifier of the term to view):
 * <a href="/modal/taxonomy/term/TID/nojs" class="ctools-use-modal">View term</a>.
 *
 * Ensure the page with such links executes the following functions (this is done in init code of modal.module):
 * ctools_include('modal');
 * ctools_modal_add_js();
 */

/**
 * Implements hook_menu().
 */
function modal_term_view_menu() {
  $items['modal/taxonomy/term/%taxonomy_term/%ctools_js'] = array(
    'title' => 'View taxonomy term',
    'page callback' => 'modal_term_view_page',
    'page arguments' => array(
      3,
      4,
    ),
    'access callback' => TRUE,
    'delivery callback' => 'ajax_deliver',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Page callback - modal: view taxonomy term.
 */
function modal_term_view_page($term, $js) {

  // Fall back if $js is not set.
  if (!$js) {
    $parameters = drupal_get_query_parameters();
    unset($_GET['destination']);
    drupal_goto('taxonomy/term/' . $term->tid, array(
      'query' => $parameters,
    ));
    return NULL;
  }

  // Fix superglobals (such as $_GET) in order to make arg() work properly.
  modal_set_path_data('taxonomy/term/' . $term->tid);
  ctools_include('modal');
  ctools_include('ajax');
  if (!user_access('access content')) {
    $commands = array(
      ctools_modal_command_display(t('Access denied'), t('You are not authorized to access this page.')),
    );
    $commands[] = ajax_command_invoke('#modalContent', 'addClass', array(
      'modal-denied-term modal-denied-term-' . $term->vocabulary_machine_name,
    ));
    drupal_alter('modal_term_view_access_denied', $commands, $term);
    return array(
      '#type' => 'ajax',
      '#commands' => $commands,
    );
  }
  $title = check_plain($term->name);
  drupal_alter('modal_term_view_title', $title, $term);
  $view_mode = 'full';
  drupal_alter('modal_term_view_mode', $view_mode, $term);
  $term_view = taxonomy_term_view($term, $view_mode);
  $commands = array();
  $commands[] = ajax_command_invoke('#modalContent', 'addClass', array(
    'modal-term modal-term-' . $term->vocabulary_machine_name,
  ));
  drupal_alter('modal_term_view', $commands, $term_view, $term);
  array_unshift($commands, ctools_modal_command_display($title, $term_view));
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}

Functions

Namesort descending Description
modal_term_view_menu Implements hook_menu().
modal_term_view_page Page callback - modal: view taxonomy term.