Skip to content

Instantly share code, notes, and snippets.

@petercossey
Last active June 25, 2018 02:11
Show Gist options
  • Save petercossey/a0942d591fa6aa486ca71e6155fc0f44 to your computer and use it in GitHub Desktop.
Save petercossey/a0942d591fa6aa486ca71e6155fc0f44 to your computer and use it in GitHub Desktop.
Drupal 7 Ctools modal example
<?php
/**
* @file
* Ctewls module
*/
/**
* Implementation of hook_menu().
*/
function ctewls_menu() {
$items = array();
$items['ctewls'] = array(
'title' => 'Show me some CTools magic!',
'page callback' => 'ctewls_main',
'access callback' => TRUE,
);
$items['ctewls/%ctools_js/popup'] = array(
'title' => 'Hello World',
'page callback' => 'ctewls_popup',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Page call back for /ctewls path
*/
function ctewls_main() {
$output = '';
ctools_include('modal');
ctools_modal_add_js();
$output = '<p style="margin-top: 100px;"><a href="/ctewls/nojs/popup" class="ctools-use-modal">hello modal</a></p>';
return $output;
}
/**
* Page/modal callback for /ctewls/nojs/popup
*/
function ctewls_popup($js = NULL) {
$title = t('I haz pop');
$output = '<p>' . t('Hello from CTewls world') . '</p>';
if ($js) {
ctools_include('modal');
ctools_modal_render($title, $output);
}
else {
drupal_set_title($title);
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment