4 * Implements hook_ctools_plugin_api().
6 function panels_ajax_tab_ctools_plugin_api() {
7 return array("version" => "1");
11 * Implementation of hook_ctools_plugin_dierctory() to let the system know
12 * we implement plugins.
14 function panels_ajax_tab_ctools_plugin_directory($module, $plugin) {
15 if ($plugin == 'content_types') {
16 return 'plugins/' .
$plugin;
21 * Implementation of hook_menu()
23 function panels_ajax_tab_menu() {
26 $items['panels_ajax_tab/%/%'] = array(
27 'title' => 'panels-ajax tab AJAX callback',
28 'description' => 'AHAJ callback for panels tabs',
29 'page callback' => 'panels_ajax_tab_ajax',
30 'page arguments' => array(1,2),
31 'access arguments' => array('access content'),
32 'type' => MENU_CALLBACK
,
39 * Implementation of hook_menu()
41 function panels_ajax_tab_theme($existing, $type, $theme, $path) {
43 'panels_ajax_tab_tabs' => array(
44 'variables' => array('minipanels' => NULL
, 'tab_container_id' => NULL
, 'context_string' => NULL
),
46 'panels_ajax_tab_container' => array(
47 'variables' => array('tab_container_id' => NULL
, 'context_string' => NULL
),
49 'panels_ajax_tab_ajax' => array(
50 'variables' => array('minipanel' => NULL
),
52 'panels_ajax_tab_tabs_edit_form' => array(
53 'render element' => 'form',
59 * AHAH call-back for preview
61 function panels_ajax_tab_ajax($panel_name, $context_string) {
62 ctools_include('context');
63 ctools_include('plugins', 'panels');
65 $mini = panels_mini_load($panel_name);
67 if ($context_string != 'none') {
68 $parts = explode(':', $context_string);
69 $entity_type = strtolower($parts[0]);
70 $entity_id = (int) $parts[1];
71 $entity = array_pop(entity_load($entity_type, array($entity_id)));
73 // If it's a node, check node-view permissions
74 if ($entity_type == 'node') {
75 if (!node_access('view', $entity)) {
76 drupal_access_denied();
81 $context_plugin = ctools_get_plugins('ctools', 'contexts', 'entity');
82 $context_plugin['keyword'] = $entity_type;
83 $context = ctools_context_create_entity(FALSE
, $entity, FALSE
, $context_plugin);
85 // Load up any contexts we might be using.
86 $context = ctools_context_match_required_contexts($mini->requiredcontexts
, array($context));
87 $mini->context
= $mini->display
->context
= ctools_context_load_contexts($mini, FALSE
, $context);
90 if (empty($mini) || !empty($mini->disabled
)) {
94 $mini->display
->owner
= $mini;
95 // unique ID of this mini.
96 $mini->display
->owner
->id
= $mini->name
;
98 // Clear the JavaScript and CSS that are not related to the panels being rendered - they already exists
99 drupal_static_reset('drupal_add_js');
100 drupal_static_reset('drupal_add_css');
102 print theme('panels_ajax_tab_ajax', array('minipanel' => $mini));
108 function theme_panels_ajax_tab_tabs($vars) {
109 foreach ($vars['minipanels'] as
$mini) {
110 $tabs[] = '<a href="#" class="panels-ajax-tab-tab" data-panel-name="'.
$mini->name.
'" data-target-id="' .
$vars['tab_container_id'] .
'" data-entity-context="' .
$vars['context_string'] .
'">' .
$mini->admin_title .
'</a>';
112 return theme('item_list', array('items' => $tabs, 'attributes' => array('class' => array('tabs', 'inline', 'panels-ajax-tab'))));
115 function theme_panels_ajax_tab_container($vars) {
116 return '<div id="panels-ajax-tab-container-' .
$vars['tab_container_id'] .
'" class="panels-ajax-tab-container"></div>';
119 function theme_panels_ajax_tab_ajax($vars) {
120 $mini = $vars['minipanel'];
121 $layout = panels_get_layout($mini->display
->layout
);
122 $panels_output = panels_render_display($mini->display
);
125 $output .
= '<?xml version="1.0" encoding="UTF-8" ?>';
127 <html version="HTML+RDFa+MathML 1.1"
128 xmlns:content="http://purl.org/rss/1.0/modules/content/"
129 xmlns:dc="http://purl.org/dc/terms/"
130 xmlns:foaf="http://xmlns.com/foaf/0.1/"
131 xmlns:og="http://ogp.me/ns#"
132 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
133 xmlns:sioc="http://rdfs.org/sioc/ns#"
134 xmlns:sioct="http://rdfs.org/sioc/types#"
135 xmlns:skos="http://www.w3.org/2004/02/skos/core#"
136 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
137 xmlns:mml="http://www.w3.org/1998/Math/MathML">
141 // Get the javascript and filter out the default misc/drupal.js - it's already been added by the calling page
142 $javascript = drupal_add_js();
143 unset($javascript['misc/drupal.js']);
144 $output .
= drupal_get_js('header', $javascript);
147 $output .
= drupal_get_css();
148 $output .
= "<link rel='stylesheet' type='text/css' href='".
base_path().
$layout['path'].
'/'.
$layout['css'].
"' />";
150 $output .
= '</head>';
152 // Print the output of the panel
154 $output .
= theme('status_messages');
155 $output .
= '<div class="panels-ajax-tab-panel panels-ajax-tab-panel-'.
str_replace('_', '-', $mini->name
).
'">';
156 $output .
= $panels_output;
158 $output .
= '</body></html>';
164 function theme_panels_ajax_tab_tabs_edit_form($variables) {
165 $form = $variables['form'];
167 // Render elements that are supposed to be on top.
168 foreach(element_children($form) as
$element) {
169 if($element == 'mini_panels') {
173 $output .
= drupal_render($form[$element]);
178 foreach(element_children($form['mini_panels']) as
$mini_panel) {
179 $form['mini_panels'][$mini_panel]['weight']['#attributes']['class'] = array('panel-weight');
182 drupal_render($form['mini_panels'][$mini_panel]['selected']),
183 drupal_render($form['mini_panels'][$mini_panel]['name']),
184 drupal_render($form['mini_panels'][$mini_panel]['weight']),
186 'class' => array('draggable'),
190 $header = array(t('Select'), t('Mini panel name'), t('Weight'));
191 $output .
= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'mini-panels-table')));
192 $output .
= drupal_render_children($form);
193 drupal_add_tabledrag('mini-panels-table', 'order', 'sibling', 'panel-weight');