[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/panels/plugins/export_ui/ -> panels_layouts_ui.class.php (source)

   1  <?php
   2  // $Id: panels_layouts_ui.class.php,v 1.1.2.8 2010/07/23 21:49:03 merlinofchaos Exp $
   3  
   4  class panels_layouts_ui extends ctools_export_ui {
   5    var $lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam egestas congue nibh, vel dictum ante posuere vitae. Cras gravida massa tempor metus eleifend sed elementum tortor scelerisque. Vivamus egestas, tortor quis luctus tristique, sem velit adipiscing risus, et tempus enim felis in massa. Morbi viverra, nisl quis rhoncus imperdiet, turpis massa vestibulum turpis, egestas faucibus nibh metus vel nunc. In hac habitasse platea dictumst. Nunc sit amet nisi quis ipsum tincidunt semper. Donec ac urna enim, et placerat arcu. Morbi eu laoreet justo. Nullam nec velit eu neque mattis pulvinar sed non libero. Sed sed vulputate erat. Fusce sit amet dui nibh.";
   6  
   7    function hook_menu(&$items) {
   8      // During updates, this can run before our schema is set up, so our
   9      // plugin can be empty.
  10      if (empty($this->plugin['menu']['items']['add'])) {
  11        return;
  12      }
  13  
  14      // Change the item to a tab on the Panels page.
  15      $this->plugin['menu']['items']['list callback']['type'] = MENU_LOCAL_TASK;
  16  
  17      // Establish a base for adding plugins
  18      $base = $this->plugin['menu']['items']['add'];
  19      // Remove the default 'add' menu item.
  20      unset($this->plugin['menu']['items']['add']);
  21  
  22      ctools_include('plugins', 'panels');
  23      $this->builders = panels_get_layout_builders();
  24      asort($this->builders);
  25      foreach ($this->builders as $name => $builder) {
  26        // Create a new menu item for the builder
  27        $item = $base;
  28        $item['title'] = !empty($builder['builder tab title']) ? $builder['builder tab title'] : 'Add ' . $builder['title'];
  29        $item['page arguments'][] = $name;
  30        $item['path'] = 'add-' . $name;
  31        $this->plugin['menu']['items']['add ' . $name] = $item;
  32      }
  33  
  34      parent::hook_menu($items);
  35    }
  36  
  37    function edit_form(&$form, &$form_state) {
  38      ctools_include('plugins', 'panels');
  39      // If the plugin is not set, then it should be provided as an argument:
  40      if (!isset($form_state['item']->plugin)) {
  41        $form_state['item']->plugin = $form_state['function args'][2];
  42      }
  43  
  44      parent::edit_form($form, $form_state);
  45  
  46      $form['category'] = array(
  47        '#type' => 'textfield',
  48        '#title' => t('Category'),
  49        '#description' => t('What category this layout should appear in. If left blank the category will be "Miscellaneous".'),
  50        '#default_value' => $form_state['item']->category,
  51      );
  52  
  53      ctools_include('context');
  54      ctools_include('display-edit', 'panels');
  55      ctools_include('content');
  56  
  57      // Provide actual layout admin UI here.
  58      // Create a display for editing:
  59      $cache_key = 'builder-' . $form_state['item']->name;
  60  
  61      // Load the display being edited from cache, if possible.
  62      if (!empty($_POST) && is_object($cache = panels_edit_cache_get($cache_key))) {
  63        $display = &$cache->display;
  64      }
  65      else {
  66        $content_types = ctools_content_get_available_types();
  67  
  68        $display->cache_key = $cache_key;
  69        panels_cache_clear('display', $cache_key);
  70        $cache = new stdClass();
  71  
  72        $display = panels_new_display();
  73        $display->did = $form_state['item']->name;
  74        $display->layout = $form_state['item']->plugin;
  75        $display->layout_settings = $form_state['item']->settings;
  76        $display->cache_key = $cache_key;
  77        $display->editing_layout = TRUE;
  78  
  79        $cache->display = $display;
  80        $cache->content_types = $content_types;
  81        $cache->display_title = FALSE;
  82        panels_edit_cache_set($cache);
  83      }
  84  
  85      // Set up lipsum content in all of the existing panel regions:
  86      $display->content = array();
  87      $display->panels = array();
  88      $custom = ctools_get_content_type('custom');
  89      $layout = panels_get_layout($display->layout);
  90  
  91      $regions = panels_get_regions($layout, $display);
  92      foreach ($regions as $id => $title) {
  93        $pane = panels_new_pane('custom', 'custom');
  94        $pane->pid = $id;
  95        $pane->panel = $id;
  96        $pane->configuration = ctools_content_get_defaults($custom, 'custom');
  97        $pane->configuration['title'] = 'Lorem Ipsum';
  98        $pane->configuration['body'] = $this->lipsum;
  99        $display->content[$id] = $pane;
 100        $display->panels[$id] = array($id);
 101      }
 102  
 103      $form_state['display'] = &$display;
 104      // Tell the Panels form not to display buttons.
 105      $form_state['no buttons'] = TRUE;
 106      $form_state['no display settings'] = TRUE;
 107  
 108      $form_state['cache_key'] = $cache_key;
 109      $form_state['content_types'] = $cache->content_types;
 110      $form_state['display_title'] = FALSE;
 111  
 112      $form_state['renderer'] = panels_get_renderer_handler('editor', $cache->display);
 113      $form_state['renderer']->cache = &$cache;
 114  
 115      $form = array_merge($form, panels_edit_display_form($form_state));
 116      // Make sure the theme will work since our form id is different.
 117      $form['#theme'] = 'panels_edit_display_form';
 118  
 119      // If we leave the standard submit handler, it'll try to reconcile
 120      // content from the input, but we've not exposed that to the user. This
 121      // makes previews work with the content we forced in.
 122      $form['preview']['button']['#submit'] = array('panels_edit_display_form_preview');
 123    }
 124  
 125    function edit_form_submit(&$form, &$form_state) {
 126      parent::edit_form_submit($form, $form_state);
 127      $form_state['item']->settings = $form_state['display']->layout_settings;
 128    }
 129  
 130    function list_form(&$form, &$form_state) {
 131      ctools_include('plugins', 'panels');
 132      $this->builders = panels_get_layout_builders();
 133      parent::list_form($form, $form_state);
 134  
 135      $categories = $plugins = array('all' => t('- All -'));
 136      foreach ($this->items as $item) {
 137        $categories[$item->category] = $item->category ? $item->category : t('Miscellaneous');
 138      }
 139  
 140      $form['top row']['category'] = array(
 141        '#type' => 'select',
 142        '#title' => t('Category'),
 143        '#options' => $categories,
 144        '#default_value' => 'all',
 145        '#weight' => -10,
 146      );
 147  
 148      foreach ($this->builders as $name => $plugin) {
 149        $plugins[$name] = $plugin['title'];
 150      }
 151  
 152      $form['top row']['plugin'] = array(
 153        '#type' => 'select',
 154        '#title' => t('Type'),
 155        '#options' => $plugins,
 156        '#default_value' => 'all',
 157        '#weight' => -9,
 158      );
 159    }
 160  
 161    function list_filter($form_state, $item) {
 162      if ($form_state['values']['category'] != 'all' && $form_state['values']['category'] != $item->category) {
 163        return TRUE;
 164      }
 165  
 166      if ($form_state['values']['plugin'] != 'all' && $form_state['values']['plugin'] != $item->plugin) {
 167        return TRUE;
 168      }
 169  
 170      return parent::list_filter($form_state, $item);
 171    }
 172  
 173    function list_sort_options() {
 174      return array(
 175        'disabled' => t('Enabled, title'),
 176        'title' => t('Title'),
 177        'name' => t('Name'),
 178        'category' => t('Category'),
 179        'storage' => t('Storage'),
 180        'plugin' => t('Type'),
 181      );
 182    }
 183  
 184    function list_build_row($item, &$form_state, $operations) {
 185      // Set up sorting
 186      switch ($form_state['values']['order']) {
 187        case 'disabled':
 188          $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
 189          break;
 190        case 'title':
 191          $this->sorts[$item->name] = $item->admin_title;
 192          break;
 193        case 'name':
 194          $this->sorts[$item->name] = $item->name;
 195          break;
 196        case 'category':
 197          $this->sorts[$item->name] = ($item->category ? $item->category : t('Miscellaneous')) . $item->admin_title;
 198          break;
 199        case 'plugin':
 200          $this->sorts[$item->name] = $item->plugin;
 201          break;
 202        case 'storage':
 203          $this->sorts[$item->name] = $item->type . $item->admin_title;
 204          break;
 205      }
 206  
 207      $type = !empty($this->builders[$item->plugin]) ? $this->builders[$item->plugin]['title'] : t('Broken/missing plugin');
 208      $category = $item->category ? check_plain($item->category) : t('Miscellaneous');
 209      $this->rows[$item->name] = array(
 210        'data' => array(
 211          array('data' => check_plain($type), 'class' => 'ctools-export-ui-type'),
 212          array('data' => check_plain($item->name), 'class' => 'ctools-export-ui-name'),
 213          array('data' => check_plain($item->admin_title), 'class' => 'ctools-export-ui-title'),
 214          array('data' => $category, 'class' => 'ctools-export-ui-category'),
 215          array('data' => theme('links', $operations), 'class' => 'ctools-export-ui-operations'),
 216        ),
 217        'title' => check_plain($item->admin_description),
 218        'class' => !empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled',
 219      );
 220    }
 221  
 222    function list_table_header() {
 223      return array(
 224        array('data' => t('Type'), 'class' => 'ctools-export-ui-type'),
 225        array('data' => t('Name'), 'class' => 'ctools-export-ui-name'),
 226        array('data' => t('Title'), 'class' => 'ctools-export-ui-title'),
 227        array('data' => t('Category'), 'class' => 'ctools-export-ui-category'),
 228        array('data' => t('Operations'), 'class' => 'ctools-export-ui-operations'),
 229      );
 230    }
 231  }


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