View source
<?php
$plugin = array(
'title' => t('Landing page'),
'page title' => t('Landing page wizard'),
'description' => t('Landing pages are simple pages that have a path, possibly a visible menu entry, and a panel layout with simple content.'),
'type' => 'panels',
'form info' => array(
'order' => array(
'basic' => t('Basic settings'),
'content' => t('Content'),
),
'forms' => array(
'basic' => array(
'form id' => 'panels_landing_page_basic',
),
'content' => array(
'form id' => 'panels_landing_page_content',
),
),
),
'default cache' => 'panels_landing_page_new_page',
'finish' => 'panels_landing_page_finish',
);
function panels_landing_page_new_page(&$cache) {
$cache->name = '';
$cache->admin_title = '';
$cache->admin_description = '';
$cache->path = '';
$cache->menu_entry = FALSE;
$cache->menu = array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
'parent' => array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
),
);
$cache->display = panels_new_display();
$cache->display->layout = 'flexible';
$cache->display->storage_type = 'page_manager';
$cache->display->storage_id = 'new';
}
function panels_landing_page_basic($form, &$form_state) {
$cache =& $form_state['wizard cache'];
ctools_include('dependent');
$form['admin_title'] = array(
'#type' => 'textfield',
'#title' => t('Administrative title'),
'#description' => t('The name of this page. This will appear in the administrative interface to easily identify it.'),
'#default_value' => $cache->admin_title,
'#required' => TRUE,
);
$form['name'] = array(
'#type' => 'machine_name',
'#title' => t('Machine name'),
'#machine_name' => array(
'exists' => 'page_manager_page_load',
'source' => array(
'admin_title',
),
),
'#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!'),
'#default_value' => $cache->name,
);
$form['admin_description'] = array(
'#type' => 'textarea',
'#title' => t('Administrative description'),
'#description' => t('A description of what this page is, does or is for, for administrative use.'),
'#default_value' => $cache->admin_description,
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#default_value' => $cache->path,
'#field_prefix' => url(NULL, array(
'absolute' => TRUE,
)) . (variable_get('clean_url', 0) ? '' : '?q='),
'#required' => TRUE,
);
$form['menu_entry'] = array(
'#type' => 'checkbox',
'#default_value' => $cache->menu_entry,
'#title' => t('Add a visible menu entry for this page'),
);
$form['menu']['#tree'] = TRUE;
$form['menu']['title'] = array(
'#title' => t('Menu title'),
'#type' => 'textfield',
'#default_value' => $cache->menu['title'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-menu-entry' => array(
1,
),
),
);
if (module_exists('menu')) {
$form['menu']['name'] = array(
'#title' => t('Menu'),
'#type' => 'select',
'#options' => menu_get_menus(),
'#default_value' => $cache->menu['name'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-menu-entry' => array(
1,
),
),
);
}
else {
$form['menu']['name'] = array(
'#type' => 'value',
'#value' => $cache->menu['name'],
);
$form['menu']['markup'] = array(
'#value' => t('Menu selection requires the activation of menu module.'),
);
}
$form['menu']['weight'] = array(
'#title' => t('Weight'),
'#type' => 'textfield',
'#default_value' => isset($cache->menu['weight']) ? $cache->menu['weight'] : 0,
'#description' => t('The lower the weight the higher/further left it will appear.'),
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-menu-entry' => array(
1,
),
),
);
ctools_include('page-wizard', 'panels');
panels_page_wizard_add_layout($form, $form_state);
$page_task = page_manager_get_task('page');
return $form;
}
function panels_landing_page_basic_validate(&$form, &$form_state) {
$test = page_manager_page_load($form_state['values']['name']);
if ($test) {
form_error($form['name'], t('That name is used by another page: @page', array(
'@page' => $test->admin_title,
)));
}
if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) {
form_error($form['name'], t('Page name must be alphanumeric or underscores only.'));
}
if (preg_match('/[%!\\?#&]/', $form_state['values']['path'])) {
form_error($form['path'], t('%, !, ?, #, or & cannot appear in the path.'));
}
$result = db_query("SELECT * FROM {menu_router} WHERE path = :path", array(
':path' => $form_state['values']['path'],
))
->fetch();
if ($result) {
form_error($form['path'], t('That path is already in use. This system cannot override existing paths.'));
return;
}
$alias = db_query('SELECT alias, source FROM {url_alias} WHERE alias = :path', array(
':path' => $form_state['values']['path'],
))
->fetchObject();
if ($alias) {
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,
)));
}
}
function panels_landing_page_basic_submit(&$form, &$form_state) {
$cache =& $form_state['wizard cache'];
$cache->name = $form_state['values']['name'];
$cache->admin_title = $form_state['values']['admin_title'];
$cache->admin_description = $form_state['values']['admin_description'];
$cache->path = $form_state['values']['path'];
$cache->menu_entry = $form_state['values']['menu_entry'];
$cache->menu['title'] = $form_state['values']['menu']['title'];
$cache->menu['weight'] = $form_state['values']['menu']['weight'];
$cache->menu['name'] = $form_state['values']['menu']['name'];
$cache->menu['type'] = $cache->menu_entry ? 'normal' : 'none';
$cache->display->layout = $form_state['values']['layout'];
$cache->display->title = $form_state['values']['admin_title'];
}
function panels_landing_page_content($form, &$form_state) {
ctools_include('page-wizard', 'panels');
panels_page_wizard_add_content($form, $form_state);
return $form;
}
function panels_landing_page_submit(&$form, &$form_state) {
panels_page_wizard_add_content_submit($form, $form_state);
}
function panels_landing_page_finish(&$form_state) {
$cache =& $form_state['wizard cache'];
$page_task = page_manager_get_task('page');
$subtask = page_manager_page_new();
$subtask->name = $cache->name;
$subtask->path = $cache->path;
$subtask->admin_title = $cache->admin_title;
$subtask->admin_description = $cache->admin_description;
$subtask->path = $cache->path;
$subtask->menu = $cache->menu;
$plugin = page_manager_get_task_handler('panel_context');
$cache->display->storage_id = $cache->name;
$handler = page_manager_new_task_handler($plugin);
$handler->conf['title'] = t('Landing page');
$handler->conf['display'] = $cache->display;
$handler->conf['pipeline'] = 'ipe';
$page = new stdClass();
page_manager_page_new_page_cache($subtask, $page);
page_manager_handler_add_to_page($page, $handler);
page_manager_save_page_cache($page);
$form_state['redirect'] = $cache->path;
}