Projet

Général

Profil

Paste
Télécharger (9,28 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / plugins / page_wizards / landing_page.inc @ a2bb1a14

1 85ad3d82 Assos Assos
<?php
2
/**
3
 * @file
4
 * A page creation wizard to quickly create simple landing pages.
5
 *
6
 * This wizard strips out a lot of features that are not normally needed for
7
 * simple landing pages, such as access control, tabs, contexts, and the
8
 * selection of a variant. It will just assume you want a panel and let you
9
 * select the layout right away. This is 2 fewer forms than the standard
10
 * add page process and it will point you at the finished page rather than
11
 * sending you directly to the edit UI when finished.
12
 *
13
 * It also will auto-enable IPE if it can.
14
 */
15
$plugin = array(
16
  'title' => t('Landing page'),
17
  'page title' => t('Landing page wizard'),
18
  'description' => t('Landing pages are simple pages that have a path, possibly a visible menu entry, and a panel layout with simple content.'),
19
20
  'type' => 'panels',
21
22
  'form info' => array(
23
    'order' => array(
24
      'basic' => t('Basic settings'),
25
      'content' => t('Content'),
26
    ),
27
28
    'forms' => array(
29
      'basic' => array(
30
        'form id' => 'panels_landing_page_basic',
31
      ),
32
      'content' => array(
33
        'form id' => 'panels_landing_page_content',
34
      ),
35
    ),
36
  ),
37
38
  'default cache' => 'panels_landing_page_new_page',
39
40
  'finish' => 'panels_landing_page_finish',
41
);
42
43
/**
44
 * Provide defaults for a new cache.
45
 *
46
 * The cache will store all our temporary data; it isn't really a page
47
 * in itself, but it does contain everything we need to make one at the end.
48
 */
49
function panels_landing_page_new_page(&$cache) {
50
  $cache->name = '';
51
  $cache->admin_title = '';
52
  $cache->admin_description = '';
53
  $cache->path = '';
54
  $cache->menu_entry = FALSE;
55
  $cache->menu = array(
56
    'type' => 'none',
57
    'title' => '',
58
    'weight' => 0,
59
    'name' => 'navigation',
60
    'parent' => array(
61
      'type' => 'none',
62
      'title' => '',
63
      'weight' => 0,
64
      'name' => 'navigation',
65
    ),
66
  );
67
  $cache->display = panels_new_display();
68
  $cache->display->layout = 'flexible';
69 2545992a Assos Assos
  $cache->display->storage_type = 'page_manager';
70
  $cache->display->storage_id = 'new';
71 85ad3d82 Assos Assos
}
72
73
/**
74
 * First page of our page creator wizard.
75
 */
76
function panels_landing_page_basic($form, &$form_state) {
77
  $cache = &$form_state['wizard cache'];
78
  ctools_include('dependent');
79
80
  $form['admin_title'] = array(
81
    '#type' => 'textfield',
82
    '#title' => t('Administrative title'),
83
    '#description' => t('The name of this page. This will appear in the administrative interface to easily identify it.'),
84
    '#default_value' => $cache->admin_title,
85
    '#required' => TRUE,
86
  );
87
88
  $form['name'] = array(
89
    '#type' => 'machine_name',
90
    '#title' => t('Machine name'),
91
    '#machine_name' => array(
92
      'exists' => 'page_manager_page_load',
93
      'source' => array('admin_title'),
94
    ),
95
    '#description' => t('The machine readable name of this page. It must be unique, and it must contain only alphanumeric characters and underscores. Once created, you will not be able to change this value!'),
96
    '#default_value' => $cache->name,
97
  );
98
99
  $form['admin_description'] = array(
100
    '#type' => 'textarea',
101
    '#title' => t('Administrative description'),
102
    '#description' => t('A description of what this page is, does or is for, for administrative use.'),
103
    '#default_value' => $cache->admin_description,
104
  );
105
106
  // path
107
  $form['path'] = array(
108
    '#type' => 'textfield',
109
    '#title' => t('Path'),
110
    '#default_value' => $cache->path,
111
    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
112
    '#required' => TRUE,
113
  );
114
115
  $form['menu_entry'] = array(
116
    '#type' => 'checkbox',
117
    '#default_value' => $cache->menu_entry,
118
    '#title' => t('Add a visible menu entry for this page'),
119
  );
120
121
  $form['menu']['#tree'] = TRUE;
122
123
  $form['menu']['title'] = array(
124
    '#title' => t('Menu title'),
125
    '#type' => 'textfield',
126
    '#default_value' => $cache->menu['title'],
127
    '#process' => array('ctools_dependent_process'),
128
    '#dependency' => array('edit-menu-entry' => array(1)),
129
  );
130
131
  // Only display the menu selector if menu module is enabled.
132
  if (module_exists('menu')) {
133
    $form['menu']['name'] = array(
134
      '#title' => t('Menu'),
135
      '#type' => 'select',
136
      '#options' => menu_get_menus(),
137
      '#default_value' => $cache->menu['name'],
138
      '#process' => array('ctools_dependent_process'),
139
    '#dependency' => array('edit-menu-entry' => array(1)),
140
    );
141
  }
142
  else {
143
    $form['menu']['name'] = array(
144
      '#type' => 'value',
145
      '#value' => $cache->menu['name'],
146
    );
147
    $form['menu']['markup'] = array(
148
      '#value' => t('Menu selection requires the activation of menu module.'),
149
    );
150
  }
151
  $form['menu']['weight'] = array(
152
    '#title' => t('Weight'),
153
    '#type' => 'textfield',
154
    '#default_value' => isset($cache->menu['weight']) ? $cache->menu['weight'] : 0,
155
    '#description' => t('The lower the weight the higher/further left it will appear.'),
156
    '#process' => array('ctools_dependent_process'),
157
    '#dependency' => array('edit-menu-entry' => array(1)),
158
  );
159
160
  ctools_include('page-wizard', 'panels');
161
  panels_page_wizard_add_layout($form, $form_state);
162
163
  // Ensure all 'page' features are loaded.
164
  $page_task = page_manager_get_task('page');
165
  return $form;
166
}
167
168
/**
169
 * Submit function to store the form data in our cache.
170
 */
171
function panels_landing_page_basic_validate(&$form, &$form_state) {
172
  // Validate that the name is ok.
173
  $test = page_manager_page_load($form_state['values']['name']);
174
  if ($test) {
175
    form_error($form['name'], t('That name is used by another page: @page', array('@page' => $test->admin_title)));
176
  }
177
178
  // Ensure name fits the rules:
179
  if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) {
180
    form_error($form['name'], t('Page name must be alphanumeric or underscores only.'));
181
  }
182
183
  // Validate that the path is ok.
184
  if (preg_match('/[%!\?#&]/', $form_state['values']['path'])) {
185
    form_error($form['path'], t('%, !, ?, #, or & cannot appear in the path.'));
186
  }
187
188
  // Check to see if something is already using the path
189
  $result = db_query("SELECT * FROM {menu_router} WHERE path = :path", array(':path' => $form_state['values']['path']))->fetch();
190
  if ($result) {
191
    form_error($form['path'], t('That path is already in use. This system cannot override existing paths.'));
192
    return;
193
  }
194
195
  // Ensure the path is not already an alias to something else.
196
  $alias = db_query('SELECT alias, source FROM {url_alias} WHERE alias = :path', array(':path' => $form_state['values']['path']))->fetchObject();
197
  if ($alias) {
198
    form_error($form['path'], t('That path is currently assigned to be an alias for @alias. This system cannot override existing aliases.', array('@alias' => $alias->src)));
199
  }
200
}
201
202
/**
203
 * Submit function to store the form data in our cache.
204
 */
205
function panels_landing_page_basic_submit(&$form, &$form_state) {
206
  $cache = &$form_state['wizard cache'];
207
  $cache->name = $form_state['values']['name'];
208
  $cache->admin_title = $form_state['values']['admin_title'];
209
  $cache->admin_description = $form_state['values']['admin_description'];
210
  $cache->path = $form_state['values']['path'];
211
  $cache->menu_entry = $form_state['values']['menu_entry'];
212
  $cache->menu['title'] = $form_state['values']['menu']['title'];
213
  $cache->menu['weight'] = $form_state['values']['menu']['weight'];
214
  $cache->menu['name'] = $form_state['values']['menu']['name'];
215
  $cache->menu['type'] = $cache->menu_entry ? 'normal' : 'none';
216
  $cache->display->layout = $form_state['values']['layout'];
217
  $cache->display->title = $form_state['values']['admin_title'];
218
}
219
220
/**
221
 * Second page of our wizard. This one provides a layout and lets the
222
 * user add content.
223
 */
224
function panels_landing_page_content($form, &$form_state) {
225
  ctools_include('page-wizard', 'panels');
226
  panels_page_wizard_add_content($form, $form_state);
227
228
  return $form;
229
}
230
231
/**
232
 * Submit function to store the form data in our cache.
233
 */
234
function panels_landing_page_submit(&$form, &$form_state) {
235
  panels_page_wizard_add_content_submit($form, $form_state);
236
}
237
238
/**
239
 * Finish callback for the wizard.
240
 *
241
 * When the wizard is finished, this callback will create the actual
242
 * page, save it, and redirect the user to view the new work.
243
 */
244
function panels_landing_page_finish(&$form_state) {
245
  $cache = &$form_state['wizard cache'];
246
247
  // Ensure all 'page' features are loaded.
248
  $page_task = page_manager_get_task('page');
249
250
  // Assemble a new page subtask.
251
  $subtask = page_manager_page_new();
252
  $subtask->name = $cache->name;
253
  $subtask->path = $cache->path;
254
  $subtask->admin_title = $cache->admin_title;
255
  $subtask->admin_description = $cache->admin_description;
256
  $subtask->path = $cache->path;
257
  $subtask->menu = $cache->menu;
258
259
  // Create the the panel context variant configured with our display
260
  $plugin = page_manager_get_task_handler('panel_context');
261
262 2545992a Assos Assos
  // Set the storage id.
263
  $cache->display->storage_id = $cache->name;
264
265 85ad3d82 Assos Assos
  // Create a new handler.
266
  $handler = page_manager_new_task_handler($plugin);
267
  $handler->conf['title'] = t('Landing page');
268
  $handler->conf['display'] = $cache->display;
269
  $handler->conf['pipeline'] = 'ipe';
270
271
  // Assemble a new $page cache and assign it our page subtask and task
272
  // handler.
273
  $page = new stdClass();
274
  page_manager_page_new_page_cache($subtask, $page);
275
  page_manager_handler_add_to_page($page, $handler);
276
277
  // Save it
278
  page_manager_save_page_cache($page);
279
280
  // Send us to the new page immediately.
281
  $form_state['redirect'] = url($cache->path);
282
}