#1824978 fix for condition when is not set
[project/panels_ajax_tab.git] / plugins / content_types / panels_ajax_tab_tabs.inc
1 <?php
2
3 $plugin = array(
4 'title' => t('AJAX Tab - Tabs'),
5 'description' => t('List of Tabs to control a container'),
6 'single' => TRUE,
7 'category' => t('AJAX Tabs'),
8 'required context' => array(
9 new ctools_context_optional(t('Entity Context'), 'entity'),
10 ),
11 'render callback' => 'panels_ajax_tab_tabs_render',
12 'edit form' => 'panels_ajax_tab_tabs_edit_form'
13 );
14
15 function panels_ajax_tab_tabs_render($subtype, $conf, $panel_args, &$contexts) {
16 static $default_tab_container_id = 0;
17 ctools_include('context');
18 ctools_include('plugins', 'panels');
19 $block = new stdClass();
20 $block->title = '';
21 $block->content = '';
22
23 // Add required JavaScript and CSS
24 drupal_add_js(drupal_get_path('module', 'panels_ajax_tab') . '/js/panels_ajax_tab.js');
25
26 // Generate the context string
27 if (!$contexts[0]->data) {
28 $context_string = 'none';
29 }
30 else {
31 $entity_type = $contexts[0]->type[2];
32 $entity_ids = entity_extract_ids($entity_type, $contexts[0]->data);
33 $entity_id = array_shift($entity_ids);
34 $context_string = $entity_type . ':' . $entity_id;
35 }
36
37 // sort and load the mini-panels
38 $minipanels = array();
39 uasort($conf['mini_panels'], function($a,$b) { return $a['weight'] - $b['weight']; });
40 foreach ($conf['mini_panels'] as $panel_name => $panel_conf) {
41 if ($panel_conf['selected']) {
42 $minipanels[] = panels_mini_load($panel_name);
43 }
44 }
45
46 // Render the tabs
47 $block->content .= theme('panels_ajax_tab_tabs', array('minipanels' => $minipanels, 'tab_container_id' => $conf['container_id'], 'context_string' => $context_string));
48
49 return $block;
50 }
51
52 function panels_ajax_tab_tabs_edit_form($form, &$form_state) {
53 $conf = $form_state['conf'];
54 $panels = panels_mini_load_all();
55 foreach($panels as $panel_name => $panel) {
56 $panels[$panel_name] = (array) $panel;
57 $panels[$panel_name] = empty($conf['mini_panels'][$panel_name]) ? $panels[$panel_name] : array_merge($panels[$panel_name],$conf['mini_panels'][$panel_name]);
58 }
59 if(!empty($conf['mini_panels'][$panel_name])) {
60 uasort($panels, function($a,$b) { return $a['weight'] - $b['weight'];});
61 }
62
63 $form['mini_panels']['#tree'] = TRUE;
64 foreach ($panels as $mini_panel) {
65 $form['mini_panels'][$mini_panel['name']] = array(
66
67 'selected' => array(
68 '#type' => 'checkbox',
69 '#default_value' => $mini_panel['selected'],
70 ),
71
72 'name' => array(
73 '#markup' => $mini_panel['admin_title'],
74 ),
75
76 'weight' => array(
77 '#type' => 'weight',
78 '#title' => t('Weight'),
79 '#default_value' => $mini_panel['weight'],
80 '#delta' => 10,
81 '#title-display' => 'invisible',
82 ),
83 );
84 }
85
86 $form['container_id'] = array(
87 '#title' => t('Container ID'),
88 '#type' => 'textfield',
89 '#description' => 'If you are using tabs in seperate pane, you must supply a unique container id string.',
90 '#default_value' => $conf['container_id'],
91 '#required' => TRUE,
92 );
93 $form['#theme'] = array('panels_ajax_tab_tabs_edit_form');
94
95 return $form;
96 }
97
98 function panels_ajax_tab_tabs_edit_form_submit(&$form, &$form_state) {
99 $form_state['conf']['mini_panels'] = $form_state['values']['mini_panels'];
100 $form_state['conf']['container_id'] = $form_state['values']['container_id'];
101 }