source: sipes/modules_contrib/panels/plugins/page_wizards/landing_page.inc

stableversion-3.0
Last change on this file was 4f375e3, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el modulo panels

  • Propiedad mode establecida a 100644
File size: 9.0 KB
Línea 
1<?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 */
49function 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}
70
71/**
72 * First page of our page creator wizard.
73 */
74function panels_landing_page_basic(&$form, &$form_state) {
75  $cache = &$form_state['cache'];
76  ctools_include('dependent');
77
78  $form['admin_title'] = array(
79    '#type' => 'textfield',
80    '#title' => t('Administrative title'),
81    '#description' => t('The name of this page. This will appear in the administrative interface to easily identify it.'),
82    '#default_value' => $cache->admin_title,
83    '#required' => TRUE,
84  );
85
86  $form['name'] = array(
87    '#type' => 'textfield',
88    '#title' => t('Machine name'),
89    '#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!'),
90    '#default_value' => $cache->name,
91    '#required' => TRUE,
92  );
93
94  $form['admin_description'] = array(
95    '#type' => 'textarea',
96    '#title' => t('Administrative description'),
97    '#description' => t('A description of what this page is, does or is for, for administrative use.'),
98    '#default_value' => $cache->admin_description,
99  );
100
101  // path
102  $form['path'] = array(
103    '#type' => 'textfield',
104    '#title' => t('Path'),
105    '#default_value' => $cache->path,
106    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
107    '#required' => TRUE,
108  );
109
110  $form['menu_entry'] = array(
111    '#type' => 'checkbox',
112    '#default_value' => $cache->menu_entry,
113    '#title' => t('Add a visible menu entry for this page'),
114  );
115
116  $form['menu']['#tree'] = TRUE;
117
118  $form['menu']['title'] = array(
119    '#title' => t('Menu title'),
120    '#type' => 'textfield',
121    '#default_value' => $cache->menu['title'],
122    '#process' => array('ctools_dependent_process'),
123    '#dependency' => array('edit-menu-entry' => array(1)),
124  );
125
126  // Only display the menu selector if menu module is enabled.
127  if (module_exists('menu')) {
128    $form['menu']['name'] = array(
129      '#title' => t('Menu'),
130      '#type' => 'select',
131      '#options' => menu_get_menus(),
132      '#default_value' => $cache->menu['name'],
133      '#process' => array('ctools_dependent_process'),
134    '#dependency' => array('edit-menu-entry' => array(1)),
135    );
136  }
137  else {
138    $form['menu']['name'] = array(
139      '#type' => 'value',
140      '#value' => $cache->menu['name'],
141    );
142    $form['menu']['markup'] = array(
143      '#value' => t('Menu selection requires the activation of menu module.'),
144    );
145  }
146  $form['menu']['weight'] = array(
147    '#title' => t('Weight'),
148    '#type' => 'textfield',
149    '#default_value' => isset($cache->menu['weight']) ? $cache->menu['weight'] : 0,
150    '#description' => t('The lower the weight the higher/further left it will appear.'),
151    '#process' => array('ctools_dependent_process'),
152    '#dependency' => array('edit-menu-entry' => array(1)),
153  );
154
155  ctools_include('page-wizard', 'panels');
156  panels_page_wizard_add_layout($form, $form_state);
157}
158
159/**
160 * Submit function to store the form data in our cache.
161 */
162function panels_landing_page_basic_validate(&$form, &$form_state) {
163  // Ensure all 'page' features are loaded.
164  $page_task = page_manager_get_task('page');
165
166  // Validate that the name is ok.
167  $test = page_manager_page_load($form_state['values']['name']);
168  if ($test) {
169    form_error($form['name'], t('That name is used by another page: @page', array('@page' => $test->admin_title)));
170  }
171
172  // Ensure name fits the rules:
173  if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) {
174    form_error($form['name'], t('Page name must be alphanumeric or underscores only.'));
175  }
176
177  // Validate that the path is ok.
178  if (preg_match('/[%!\?#&]/', $form_state['values']['path'])) {
179    form_error($form['path'], t('%, !, ?, #, or & cannot appear in the path.'));
180  }
181
182  // Check to see if something is already using the path
183  $result = db_query("SELECT * FROM {menu_router} WHERE path = '%s'", $form_state['values']['path']);
184  while ($router = db_fetch_object($result)) {
185    form_error($form['path'], t('That path is already in use. This system cannot override existing paths.'));
186    return;
187  }
188
189  // Ensure the path is not already an alias to something else.
190  $result = db_query("SELECT src, dst FROM {url_alias} WHERE dst = '%s'", $form_state['values']['path']);
191  if ($alias = db_fetch_object($result)) {
192    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)));
193  }
194}
195
196/**
197 * Submit function to store the form data in our cache.
198 */
199function panels_landing_page_basic_submit(&$form, &$form_state) {
200  $cache = &$form_state['cache'];
201  $cache->name = $form_state['values']['name'];
202  $cache->admin_title = $form_state['values']['admin_title'];
203  $cache->admin_description = $form_state['values']['admin_description'];
204  $cache->path = $form_state['values']['path'];
205  $cache->menu_entry = $form_state['values']['menu_entry'];
206  $cache->menu['title'] = $form_state['values']['menu']['title'];
207  $cache->menu['weight'] = $form_state['values']['menu']['weight'];
208  $cache->menu['name'] = $form_state['values']['menu']['name'];
209  $cache->menu['type'] = $cache->menu_entry ? 'normal' : 'none';
210  $cache->display->layout = $form_state['values']['layout'];
211  $cache->display->title = $form_state['values']['admin_title'];
212}
213
214/**
215 * Second page of our wizard. This one provides a layout and lets the
216 * user add content.
217 */
218function panels_landing_page_content(&$form, &$form_state) {
219  ctools_include('page-wizard', 'panels');
220  panels_page_wizard_add_content($form, $form_state);
221}
222
223/**
224 * Submit function to store the form data in our cache.
225 */
226function panels_landing_page_submit(&$form, &$form_state) {
227  panels_page_wizard_add_content_submit($form, $form_state);
228}
229
230/**
231 * Finish callback for the wizard.
232 *
233 * When the wizard is finished, this callback will create the actual
234 * page, save it, and redirect the user to view the new work.
235 */
236function panels_landing_page_finish(&$form_state) {
237  $cache = &$form_state['cache'];
238
239  // Ensure all 'page' features are loaded.
240  $page_task = page_manager_get_task('page');
241
242  // Assemble a new page subtask.
243  $subtask = page_manager_page_new();
244  $subtask->name = $cache->name;
245  $subtask->path = $cache->path;
246  $subtask->admin_title = $cache->admin_title;
247  $subtask->admin_description = $cache->admin_description;
248  $subtask->path = $cache->path;
249  $subtask->menu = $cache->menu;
250
251  // Create the the panel context variant configured with our display
252  $plugin = page_manager_get_task_handler('panel_context');
253
254  // Create a new handler.
255  $handler = page_manager_new_task_handler($plugin);
256  $handler->conf['title'] = t('Landing page');
257  $handler->conf['display'] = $cache->display;
258  $handler->conf['pipeline'] = 'ipe';
259
260  // Assemble a new $page cache and assign it our page subtask and task
261  // handler.
262  $page = new stdClass();
263  page_manager_page_new_page_cache($subtask, $page);
264  page_manager_handler_add_to_page($page, $handler);
265
266  // Save it
267  page_manager_save_page_cache($page);
268
269  // Send us to the new page immediately.
270  $form_state['redirect'] = url($cache->path);
271}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.