Finally i resolved the hard work of making drupal menu system calling a page in a thickbox “view”.
In the last post i missed some things that in this day i learned.
The first thing to know it’s the drupal menu system. The menus in drupal works great but are not so flexible like their cms. Once a menu link is clicked, the menu system with a series of map tables and hooks checks the original menu link that fired the request and go through http requests to the browser for displaying the target page.
This kind of work isn’t the same of a simple static href link, in fact the thickbox module works great with these links because the request fired by the click event passes through him.
In the first case, that is my own, we must intercept the call of menu system. i tried by Jquery onload modification of the <li><a> tags attributes, either with adding the onload event, either with other tricks but the only things i could add are described in the previous post.
Then i added this code on the top of the page.tpl.php on a section reserved to jquery scripts:
//simple modification to some menu element’s class to enable thickbox
$(‘#menu-182 a’).addClass(‘thickbox’);//add to menu “item” the thickbox
$(‘#menu-182 a’).attr(“href”, “thickbox1″);
//some tricks to display thickbox on menu link click
var norm=’?height=300&width=300′;//the thickbox normal option
var iframe=’?keepThis=true&TB_iframe=true&height=250&width=400′;//iframed content
var iframemodal= ‘?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true’;
//first of all we must check the request uri
<?php $curi = urldecode(request_uri());
if($curi==”/thickbox1″){
?>
tb_show(“Libri Esteri”,”http://mysite/page_in_thickbox”+iframemodal,”");
<?php //return drupal_goto();
}?>
Some little explanation, the first line is the onload modification of the menu-item’s class and href.
With this modification i can intercept the fire event happened with the click on this element.
After that i’ve defined a series of jscript variables with some common options of thickbox, to use manually when i would change the visualization.
In the end, with a check on the uri passed with $_GET variable in php i can check the page target, if it’s the right that i would intercept i call the function that display the thickboxed content.
But there is a problem. Infact in this manner, the page displayed under the thickbox on the screen is the same, and i don’t want this poor work.
The solution is in some little passes. We first must define a new content type, for esample, “thickbox”.
We then can create a sample content and assign to it a clean url.
A problem with the dinamically loaded content in thickbox on drupal is a complete page load on the thickbox, with sidebars and so on, but we will display only the brief content of the node. We then have to add a simple file page-thickbox.tpl.php(thickbox in my case, but must comply with your content type name). This file it’s a simple version of your page.tpl.php, without all unnecessary things.
Now we add at the top of the page.tpl.php this snippet of code:
<?php
if ($node->type == “thickbox” || $node->type == “popup”) {
include ‘page-thickbox.tpl.php’;
return;
}
?>
Now the drupal system when laod a page check if the content type is “thickbox”.
In the code above we have checked an url called “thickbox1″, this url in my system doesn’t exist, but it’s used to intercept the call. If we will make the things better, we must check, in the php code above some things in the url, in fact if we would like to use some other links in menus, we must differentiate the request url, e.g. thickbox1,thickbox2 etc.., in this case we can check for an identifier for example thickbox&1 to redirect the correct page to thickbox.
And the page displayed under the thickbox? For now is the typical Not Found page of Drupal, but with some intelligent tricks we’ve a good system also with a page that point to the home page for example.
Merry Christmas to all!