[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/panels/plugins/page_wizards/ -> landing_page.inc (source)

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


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7