modal_node_view.module in Modal operations 7
Allows node viewing in modal window.
@example Create links with the following href and class attributes (NID is the identifier of the node to view): <a href="/modal/node/NID/nojs" class="ctools-use-modal">View node</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_node_view/modal_node_view.moduleView source
<?php
/**
* @file
* Allows node viewing in modal window.
*
* @example
* Create links with the following href and class attributes (NID is the identifier of the node to view):
* <a href="/modal/node/NID/nojs" class="ctools-use-modal">View node</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_node_view_menu() {
$items['modal/node/%node/%ctools_js'] = array(
'title' => 'View node',
'page callback' => 'modal_node_view_page',
'page arguments' => array(
2,
3,
),
'access callback' => TRUE,
'delivery callback' => 'ajax_deliver',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Page callback - modal: view node.
*/
function modal_node_view_page($node, $js) {
// Fall back if $js is not set.
if (!$js) {
$parameters = drupal_get_query_parameters();
unset($_GET['destination']);
drupal_goto('node/' . $node->nid, array(
'query' => $parameters,
));
return NULL;
}
// Fix superglobals (such as $_GET) in order to make arg() work properly.
modal_set_path_data('node/' . $node->nid);
ctools_include('modal');
ctools_include('ajax');
if (!node_access('view', $node)) {
$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-node modal-denied-node-' . $node->type,
));
drupal_alter('modal_node_view_access_denied', $commands, $node);
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
$title = check_plain($node->title);
drupal_alter('modal_node_view_title', $title, $node);
$view_mode = 'full';
drupal_alter('modal_node_view_mode', $view_mode, $node);
$node_view = node_view($node, $view_mode);
$commands = array();
$commands[] = ajax_command_invoke('#modalContent', 'addClass', array(
'modal-node modal-node-' . $node->type,
));
drupal_alter('modal_node_view', $commands, $node_view, $node);
array_unshift($commands, ctools_modal_command_display($title, $node_view));
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
Functions
Name![]() |
Description |
---|---|
modal_node_view_menu | Implements hook_menu(). |
modal_node_view_page | Page callback - modal: view node. |