Skip to content

Instantly share code, notes, and snippets.

@inbalj
Created March 30, 2016 05:26
Show Gist options
  • Select an option

  • Save inbalj/2297e81afbe4f4915a65a92a61aa8ad3 to your computer and use it in GitHub Desktop.

Select an option

Save inbalj/2297e81afbe4f4915a65a92a61aa8ad3 to your computer and use it in GitHub Desktop.
ctools modal
// paste this in a new module
function module_hook_init() {
ctools_include('ajax');
ctools_include('modal');
// Add CTools' javascript to the page.
ctools_modal_add_js();
// Create our own javascript that will be used to theme a modal.
$popup_style = array(
'MessagePopup' => array(
'modalSize' => array(
'type' => 'fixed',
'width' => 1000,
'height' => 680,
'addWidth' => 10,
'addHeight' => 10,
'contentRight' => 0,
'contentBottom' => 0,
),
'modalOptions' => array(
'opacity' => .6,
'background-color' => '#fff',
),
'throbber'=> '',
'animation' => 'fadeIn',
'modalTheme' => 'message_modal',
),
);
// Add the settings array defined above to Drupal 7's JS settings:
drupal_add_js($popup_style, 'setting');
}
function module_hook_menu() {
$items = array();
$items['oppertunity/%/%'] = array(
'page callback' => 'module_hook_oppertunity_popup',
'page arguments' => array(1, 2),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
// This works on field collections
function module_hook_oppertunity_popup($id = NULL, $js = NULL) {
if ($id == NULL) {
return 'No node id was sent. Error.';
}
$fc_item = field_collection_item_load($id);
$content = render(entity_view('field_collection_item', array($fc_item),'popup_display'));
if (!$js) {
return render($field);
}
else {
ctools_include('ajax');
ctools_include('modal');
$output = ctools_modal_render('', $content) ;
return $output;
}
}
// for node
function module_hook_oppertunity_popup($nid,$js = NULL) {
$node = node_load($nid);
if(!$js) {
return render(node_view($node, '', NULL));
}
$_SESSION['product_title'] = $node->title;
ctools_include('modal');
ctools_include('ajax');
$contents = render(node_view($node, 'full', NULL));
return ctools_modal_render($node->title, $contents) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment