Projet

Général

Profil

Paste
Télécharger (5,12 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / ctools / includes / page-wizard.inc @ a5572547

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * Fetch metadata on a specific page_wizard plugin.
5
 *
6
 * @param $page_wizard
7
 *   Name of a panel page_wizard.
8
 *
9
 * @return
10
 *   An array with information about the requested panel page_wizard.
11
 */
12
function page_manager_get_page_wizard($page_wizard) {
13
  ctools_include('plugins');
14
  return ctools_get_plugins('page_manager', 'page_wizards', $page_wizard);
15
}
16
17
/**
18
 * Fetch metadata for all page_wizard plugins.
19
 *
20
 * @return
21
 *   An array of arrays with information about all available panel page_wizards.
22
 */
23
function page_manager_get_page_wizards() {
24
  ctools_include('plugins');
25
  return ctools_get_plugins('page_manager', 'page_wizards');
26
}
27
28
/**
29
 * Get the cached changes to a given wizard.
30
 *
31
 * @return
32
 *   A $cache object or a clean cache object if none could be loaded.
33
 */
34
function page_manager_get_wizard_cache($plugin) {
35
  if (is_string($plugin)) {
36
    $plugin = page_manager_get_page_wizard($plugin);
37
  }
38
39
  if (empty($plugin)) {
40
    return;
41
  }
42
43
  ctools_include('object-cache');
44
45
  // Since contexts might be cache, include this so they load.
46
  ctools_include('context');
47
  $cache = ctools_object_cache_get('page_manager_page_wizard', $plugin['name']);
48
  if (!$cache) {
49
    $cache = page_manager_make_wizard_cache($plugin);
50
  }
51
52
  return $cache;
53
}
54
55
function page_manager_make_wizard_cache($plugin) {
56
  $cache = new stdClass;
57
  $cache->plugin = $plugin;
58
  if ($function = ctools_plugin_get_function($plugin, 'default cache')) {
59
    $function($cache);
60
  }
61
62
  return $cache;
63
}
64
65
/**
66
 * Store changes to a task handler in the object cache.
67
 */
68
function page_manager_set_wizard_cache($cache) {
69
  ctools_include('object-cache');
70
  ctools_object_cache_set('page_manager_page_wizard', $cache->plugin['name'], $cache);
71
}
72
73
/**
74
 * Remove an item from the object cache.
75
 */
76
function page_manager_clear_wizard_cache($name) {
77
  ctools_include('object-cache');
78
  ctools_object_cache_clear('page_manager_page_wizard', $name);
79
}
80
81
/**
82
 * Menu callback for the page wizard.
83
 */
84
function page_manager_page_wizard($name, $step = NULL) {
85
  $plugin = page_manager_get_page_wizard($name);
86
  if (!$plugin) {
87
    return MENU_NOT_FOUND;
88
  }
89
90
  // Check for simple access string on plugin.
91
  if (!empty($plugin['access']) && !user_access($plugin['access'])) {
92
    return MENU_ACCESS_DENIED;
93
  }
94
95
  // Check for possibly more complex access callback on plugin.
96
  if ($function = ctools_plugin_get_function($plugin, 'access callback') && !$function($plugin)) {
97
    return MENU_ACCESS_DENIED;
98
  }
99
100
  // Create a basic wizard.in form info array and merge it with the
101
  // plugin's.
102
  $form_info = array(
103
    'id' => 'page_manager_page_wizard',
104
    'show trail' => TRUE,
105
    'show back' => TRUE,
106
    'show return' => FALSE,
107
    'show cancel' => FALSE,
108
    'next callback' => 'page_manager_page_wizard_next',
109
    'finish callback' => 'page_manager_page_wizard_finish',
110
111
    'path' => "admin/structure/pages/wizard/$name/%step",
112
  );
113
114
  $form_info = array_merge_recursive($form_info, $plugin['form info']);
115
116
  // If step is unset, go with the basic step.
117
  if (!isset($step)) {
118
    $step = current(array_keys($form_info['order']));
119
    $cache = page_manager_make_wizard_cache($plugin);
120
  }
121
  else {
122
    $cache = page_manager_get_wizard_cache($plugin);
123
  }
124
125
  ctools_include('wizard');
126
  $form_state = array(
127
    'plugin' => $plugin,
128
    'wizard cache' => $cache,
129
    'type' => 'edit',
130
    'rerender' => TRUE,
131
    'step' => $step,
132
  );
133
134
  if (isset($plugin['page title'])) {
135
    drupal_set_title($plugin['page title']);
136
  }
137
138
  if ($function = ctools_plugin_get_function($form_state['plugin'], 'start')) {
139
    $function($form_info, $step, $form_state);
140
  }
141
142
  $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
143
  return $output;
144
}
145
146
/**
147
 * Callback generated when the add page process is finished.
148
 */
149
function page_manager_page_wizard_finish(&$form_state) {
150
  if ($function = ctools_plugin_get_function($form_state['plugin'], 'finish')) {
151
    $function($form_state);
152
  }
153
154
  page_manager_clear_wizard_cache($form_state['wizard cache']->plugin['name']);
155
}
156
157
/**
158
 * Callback generated when the 'next' button is clicked.
159
 *
160
 * All we do here is store the cache.
161
 */
162
function page_manager_page_wizard_next(&$form_state) {
163
  if ($function = ctools_plugin_get_function($form_state['plugin'], 'next')) {
164
    $function($form_state);
165
  }
166
167
  page_manager_set_wizard_cache($form_state['wizard cache']);
168
}
169
170
/**
171
 * Provide a simple administrative list of all wizards.
172
 *
173
 * This is called as a page callback, but can also be used by any module
174
 * that wants to get a list of wizards for its type.
175
 */
176
function page_manager_page_wizard_list($type = NULL) {
177
  $plugins = page_manager_get_page_wizards();
178
  if (empty($plugins)) {
179
    return '<p>' . t('There are no wizards available at this time.') . '</p>';
180
  }
181
182
  uasort($plugins, 'ctools_plugin_sort');
183
184
  $output = '<dl class="page-manager-wizards">';
185
  foreach ($plugins as $id => $plugin) {
186
    if (!$type || (isset($plugin['type']) && $plugin['type'] == $type)) {
187
      $output .= '<dt>' . l($plugin['title'], 'admin/structure/pages/wizard/' . $id) . '</dt>';
188
      $output .= '<dd class="description">' . $plugin['description'] . '</dd>';
189
    }
190
  }
191
  $output .= '</dl>';
192
193
  return $output;
194
}