[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: node_override.inc,v 1.1.2.2 2010/08/30 22:32:55 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Page wizard that can create a variant on the node_view to take over a node
   7   * for a particular type.
   8   *
   9   * This wizard does a lot that's cut and pasted from exports. We can get away
  10   * with this because we know exports tend to remain relatively backward
  11   * compatible, and because we know that our context IDs are locked in the
  12   * node_view page.
  13   */
  14  $plugin = array(
  15    'title' => t('Node template'),
  16    'page title' => t('Node template wizard'),
  17    'description' => t('The node page wizard can help you override the node page for a type of node.'),
  18  
  19    'type' => 'panels',
  20  
  21    'form info' => array(
  22      'order' => array(
  23        'type' => t('Select node type'),
  24        'content' => t('Content'),
  25      ),
  26  
  27      'forms' => array(
  28        'type' => array(
  29          'form id' => 'panels_node_override_basic',
  30        ),
  31        'content' => array(
  32          'form id' => 'panels_node_override_content',
  33        ),
  34      ),
  35    ),
  36  
  37    'default cache' => 'panels_node_override_new_page',
  38  
  39    'start' => 'panels_node_override_start',
  40    'finish' => 'panels_node_override_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_node_override_new_page(&$cache) {
  50    $cache->type = '';
  51    $cache->display = panels_new_display();
  52    $cache->display->layout = 'flexible';
  53  }
  54  
  55  /**
  56   * Callback called prior to the wizard starting up on every page
  57   * load.
  58   */
  59  function panels_node_override_start($form_info, $step, &$form_state) {
  60    $form_state['page'] = page_manager_get_page_cache('node_view');
  61    if (!empty($form_state['page']->locked)) {
  62      $account  = user_load($form_state['page']->locked->uid);
  63      $name     = theme('username', $account);
  64      $lock_age = format_interval(time() - $form_state['page']->locked->updated);
  65      $break    = url(page_manager_edit_url($form_state['page']->task_name, array('actions', 'break-lock')));
  66  
  67      drupal_set_message(t('WARNING! The node_view is being edited by user !user, and is therefore locked from editing by others. This wizard cannot create a new node override while this page is locked. This lock is !age old. Click here to <a href="!break">break this lock</a>.', array('!user' => $name, '!age' => $lock_age, '!break' => $break)), 'warning');
  68    }
  69  }
  70  
  71  /**
  72   * First page of our page creator wizard.
  73   */
  74  function panels_node_override_basic(&$form, &$form_state) {
  75    $types = node_get_types();
  76    $form_state['types'] = $types;
  77  
  78    $already_done = array();
  79    // Figure out which types already have variants assigned to them.
  80    foreach ($form_state['page']->handlers as $name => $handler) {
  81      if ($handler->handler == 'panel_context' && !empty($handler->conf['access']['plugins'])) {
  82        foreach ($handler->conf['access']['plugins'] as $plugin) {
  83          if ($plugin['name'] == 'node_type') {
  84            foreach ($plugin['settings']['type'] as $type) {
  85              $already_done[$type] = $name;
  86            }
  87          }
  88        }
  89      }
  90    }
  91  
  92    if ($already_done) {
  93      $items = array();
  94      foreach ($already_done as $type => $handler_id) {
  95        $items[] = check_plain($types[$type]->name) . ' ' . l(t('[Edit]'), page_manager_edit_url($form_state['page']->task_name, array('handlers', $handler_id, 'content')));
  96      }
  97  
  98      $form['already_done'] = array(
  99        '#type' => 'item',
 100        '#title' => t('Existing node templates'),
 101        '#value' => theme('item_list', $items),
 102      );
 103    }
 104  
 105    $options = array();
 106    foreach ($types as $name => $type) {
 107      if (empty($already_done[$name])) {
 108        $options[$name] = $type->name;
 109      }
 110    }
 111  
 112    $form['type'] = array(
 113      '#type' => 'select',
 114      '#title' => t('Node type'),
 115      '#options' => $options,
 116      '#default_value' => $form_state['cache']->type,
 117    );
 118  
 119    ctools_include('page-wizard', 'panels');
 120    panels_page_wizard_add_layout($form, $form_state);
 121  }
 122  
 123  /**
 124   * Submit function to store the form data in our cache.
 125   */
 126  function panels_node_override_basic_submit(&$form, &$form_state) {
 127    $cache = &$form_state['cache'];
 128    $cache->display->layout = $form_state['values']['layout'];
 129    $cache->type = $form_state['values']['type'];
 130  
 131    // Create a new handler object and cache it; this way we can use the
 132    // handler object for retrieving contexts properly.
 133    // Create the the panel context variant configured with our display
 134    $plugin = page_manager_get_task_handler('panel_context');
 135  
 136    // Create a new handler.
 137    $cache->handler = page_manager_new_task_handler($plugin);
 138    $cache->handler->conf['title'] = $form_state['types'][$cache->type]->name;
 139    $cache->handler->conf['pipeline'] = 'ipe';
 140    $cache->handler->conf['access'] = array(
 141      'plugins' => array(
 142        0 => array(
 143          'name' => 'node_type',
 144          'settings' => array(
 145            'type' => array(
 146              $cache->type => $cache->type,
 147            ),
 148          ),
 149          'context' => 'argument_nid_1',
 150          'not' => FALSE,
 151        ),
 152      ),
 153      'logic' => 'and',
 154    );
 155  
 156    // Find a region by trying some basic main content region IDs.
 157    $layout = panels_get_layout($form_state['values']['layout']);
 158    $regions = panels_get_regions($layout, $cache->display);
 159    foreach (array('center', 'middle', 'content', 'main') as $candidate) {
 160      if (!empty($regions[$candidate])) {
 161        $region = $candidate;
 162        break;
 163      }
 164    }
 165  
 166    // If all of the above failed, use the first region.
 167    if (empty($region)) {
 168      $keys = array_keys($regions);
 169      $region = reset($keys);
 170    }
 171  
 172    // Populate the layout with content. This is from an export, with minor
 173    // changes to ensure defaults are correct and to add stuff to the proper region.
 174    $pane = new stdClass;
 175    $pane->pid = 'new-1';
 176    $pane->panel = $region;
 177    $pane->type = 'node_content';
 178    $pane->subtype = 'node_content';
 179    $pane->shown = TRUE;
 180    $pane->access = array();
 181    $pane->configuration = array(
 182      'links' => 1,
 183      'page' => 1,
 184      'no_extras' => 0,
 185      'override_title' => 0,
 186      'override_title_text' => '',
 187      'identifier' => '',
 188      'link' => 0,
 189      'leave_node_title' => 0,
 190      'context' => 'argument_nid_1',
 191      'build_mode' => 'full',
 192    );
 193    $pane->cache = array();
 194    $pane->style = array(
 195      'settings' => NULL,
 196    );
 197    $pane->css = array();
 198    $pane->extras = array();
 199    $pane->position = 0;
 200    $cache->display->content['new-1'] = $pane;
 201    $cache->display->panels[$region][0] = 'new-1';
 202    $pane = new stdClass;
 203    $pane->pid = 'new-2';
 204    $pane->panel = $region;
 205    $pane->type = 'node_comments';
 206    $pane->subtype = 'node_comments';
 207    $pane->shown = TRUE;
 208    $pane->access = array();
 209    $pane->configuration = array(
 210      'mode' => variable_get('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED),
 211      'order' => variable_get('comment_default_order', COMMENT_ORDER_NEWEST_FIRST),
 212      'comments_per_page' => variable_get('comment_default_per_page', '50'),
 213      'context' => 'argument_nid_1',
 214      'override_title' => 0,
 215      'override_title_text' => '',
 216    );
 217    $pane->cache = array();
 218    $pane->style = array(
 219      'settings' => NULL,
 220    );
 221    $pane->css = array();
 222    $pane->extras = array();
 223    $pane->position = 1;
 224    $cache->display->content['new-2'] = $pane;
 225    $cache->display->panels[$region][1] = 'new-2';
 226    $pane = new stdClass;
 227    $pane->pid = 'new-3';
 228    $pane->panel = $region;
 229    $pane->type = 'node_comment_form';
 230    $pane->subtype = 'node_comment_form';
 231    $pane->shown = TRUE;
 232    $pane->access = array();
 233    $pane->configuration = array(
 234      'anon_links' => 1,
 235      'context' => 'argument_nid_1',
 236      'override_title' => 0,
 237      'override_title_text' => '',
 238    );
 239    $pane->cache = array();
 240    $pane->style = array(
 241      'settings' => NULL,
 242    );
 243    $pane->css = array();
 244    $pane->extras = array();
 245    $pane->position = 2;
 246    $cache->display->content['new-3'] = $pane;
 247    $cache->display->panels[$region][2] = 'new-3';
 248  
 249    $task = page_manager_get_task('node_view');
 250    ctools_include('context');
 251    ctools_include('context-task-handler');
 252    $cache->context = ctools_context_handler_get_all_contexts($task, NULL, $cache->handler);
 253  
 254  }
 255  
 256  /**
 257   * Second page of our wizard. This one provides a layout and lets the
 258   * user add content.
 259   */
 260  function panels_node_override_content(&$form, &$form_state) {
 261    ctools_include('page-wizard', 'panels');
 262    panels_page_wizard_add_content($form, $form_state);
 263  }
 264  
 265  /**
 266   * Store changes to the display.
 267   */
 268  function panels_node_override_content_submit(&$form, &$form_state) {
 269    panels_page_wizard_add_content_submit($form, $form_state);
 270  }
 271  
 272  /**
 273   * Complete the wizard, create a new variant, and send them to the
 274   * edit screen of that variant.
 275   */
 276  function panels_node_override_finish(&$form_state) {
 277    $page = &$form_state['page'];
 278    $cache = &$form_state['cache'];
 279  
 280    // Add the new handler to the page
 281    $cache->handler->conf['display'] = $cache->display;
 282    page_manager_handler_add_to_page($page, $cache->handler);
 283  
 284    // Save it
 285    page_manager_save_page_cache($page);
 286  
 287    // Send us to the page manager edit form for this.
 288    $form_state['redirect'] = url(page_manager_edit_url('node_view', array('handlers', $cache->handler->name, 'content')));
 289    drupal_set_message(t('Your node template has been created.'));
 290  }


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