[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/ctools/stylizer/plugins/export_ui/ -> stylizer_ui.class.php (source)

   1  <?php
   2  // $Id: stylizer_ui.class.php,v 1.1.2.3 2010/08/20 22:11:40 merlinofchaos Exp $
   3  
   4  /**
   5   * UI class for Stylizer.
   6   */
   7  class stylizer_ui extends ctools_export_ui {
   8  
   9    function access($op, $item) {
  10      $access = parent::access($op, $item);
  11      if ($op == 'add' && $access && empty($this->base_types)) {
  12       // Make sure there are base styles defined.
  13       $access = FALSE;
  14      }
  15      return $access;
  16    }
  17  
  18    function list_form(&$form, &$form_state) {
  19      ctools_include('stylizer');
  20      parent::list_form($form, $form_state);
  21  
  22      $all = array('all' => t('- All -'));
  23  
  24      if (empty($this->base_types)) {
  25        // Give a warning about the missing base styles.
  26        drupal_set_message($this->plugin['strings']['message']['missing base type'], 'warning');
  27      }
  28  
  29      $types = $all;
  30      foreach ($this->base_types as $module => $info) {
  31        foreach ($info as $key => $base_type) {
  32          $types[$module . '-' . $key] = $base_type['title'];
  33        }
  34      }
  35  
  36      $form['top row']['type'] = array(
  37        '#type' => 'select',
  38        '#title' => t('Type'),
  39        '#options' => $types,
  40        '#default_value' => 'all',
  41        '#weight' => -10,
  42        '#attributes' => array('class' => 'ctools-auto-submit'),
  43      );
  44  
  45      $plugins = ctools_get_style_bases();
  46      $form_state['style_plugins'] = $plugins;
  47  
  48      $options = $all;
  49      // @todo base should use $module . '-' . $name
  50      foreach ($plugins as $name => $plugin) {
  51        $options[$name] = $plugin['title'];
  52      }
  53  
  54      $form['top row']['base'] = array(
  55        '#type' => 'select',
  56        '#title' => t('Base'),
  57        '#options' => $all + $options,
  58        '#default_value' => 'all',
  59        '#weight' => -9,
  60        '#attributes' => array('class' => 'ctools-auto-submit'),
  61      );
  62    }
  63  
  64    function list_sort_options() {
  65      return array(
  66        'disabled' => t('Enabled, title'),
  67        'title' => t('Title'),
  68        'name' => t('Name'),
  69        'base' => t('Base'),
  70        'type' => t('Type'),
  71        'storage' => t('Storage'),
  72      );
  73    }
  74  
  75    function list_filter($form_state, $item) {
  76      if (empty($form_state['style_plugins'][$item->settings['style_base']])) {
  77        $this->style_plugin = array(
  78          'name' => 'broken',
  79          'title' => t('Missing plugin'),
  80          'type' => t('Unknown'),
  81          'module' => '',
  82        );
  83      }
  84      else {
  85        $this->style_plugin = $form_state['style_plugins'][$item->settings['style_base']];
  86      }
  87  
  88      // This isn't really a field, but by setting this we can list it in the
  89      // filter fields and have the search box pick it up.
  90      $item->plugin_title = $this->style_plugin['title'];
  91  
  92      if ($form_state['values']['type'] != 'all') {
  93        list($module, $type) = explode('-', $form_state['values']['type']);
  94        if ($module != $this->style_plugin['module'] || $type != $this->style_plugin['type']) {
  95          return TRUE;
  96        }
  97      }
  98  
  99      if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $this->style_plugin['name']) {
 100        return TRUE;
 101      }
 102  
 103      return parent::list_filter($form_state, $item);
 104    }
 105  
 106    function list_search_fields() {
 107      $fields = parent::list_search_fields();
 108      $fields[] = 'plugin_title';
 109      return $fields;
 110    }
 111  
 112    function list_build_row($item, &$form_state, $operations) {
 113      // Set up sorting
 114      switch ($form_state['values']['order']) {
 115        case 'disabled':
 116          $this->sorts[$item->name] = empty($item->disabled) . $item->admin_title;
 117          break;
 118        case 'title':
 119          $this->sorts[$item->name] = $item->admin_title;
 120          break;
 121        case 'name':
 122          $this->sorts[$item->name] = $item->name;
 123          break;
 124        case 'type':
 125          $this->sorts[$item->name] = $this->style_plugin['type'] . $item->admin_title;
 126          break;
 127        case 'base':
 128          $this->sorts[$item->name] = $this->style_plugin['title'] . $item->admin_title;
 129          break;
 130        case 'storage':
 131          $this->sorts[$item->name] = $item->type . $item->admin_title;
 132          break;
 133      }
 134  
 135      if (!empty($this->base_types[$this->style_plugin['module']][$this->style_plugin['type']])) {
 136        $type = $this->base_types[$this->style_plugin['module']][$this->style_plugin['type']]['title'];
 137      }
 138      else {
 139        $type = t('Unknown');
 140      }
 141  
 142      $this->rows[$item->name] = array(
 143        'data' => array(
 144          array('data' => $type, 'class' => 'ctools-export-ui-type'),
 145          array('data' => check_plain($item->name), 'class' => 'ctools-export-ui-name'),
 146          array('data' => check_plain($item->admin_title), 'class' => 'ctools-export-ui-title'),
 147          array('data' => check_plain($this->style_plugin['title']), 'class' => 'ctools-export-ui-base'),
 148          array('data' => check_plain($item->type), 'class' => 'ctools-export-ui-storage'),
 149          array('data' => theme('links', $operations), 'class' => 'ctools-export-ui-operations'),
 150        ),
 151        'title' => check_plain($item->admin_description),
 152        'class' => !empty($item->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled',
 153      );
 154    }
 155  
 156    function list_table_header() {
 157      return array(
 158        array('data' => t('Type'), 'class' => 'ctools-export-ui-type'),
 159        array('data' => t('Name'), 'class' => 'ctools-export-ui-name'),
 160        array('data' => t('Title'), 'class' => 'ctools-export-ui-title'),
 161        array('data' => t('Base'), 'class' => 'ctools-export-ui-base'),
 162        array('data' => t('Storage'), 'class' => 'ctools-export-ui-storage'),
 163        array('data' => t('Operations'), 'class' => 'ctools-export-ui-operations'),
 164      );
 165    }
 166  
 167    function init($plugin) {
 168      ctools_include('stylizer');
 169      $this->base_types = ctools_get_style_base_types();
 170  
 171      parent::init($plugin);
 172    }
 173  
 174    function get_wizard_info(&$form_state) {
 175      $form_info = parent::get_wizard_info($form_state);
 176      ctools_include('stylizer');
 177  
 178      // For add forms, we have temporarily set the 'form type' to include
 179      // the style type so the default wizard_info can find the path. If
 180      // we did that, we have to put it back.
 181      if (!empty($form_state['type'])) {
 182        $form_state['form type'] = 'add';
 183        $form_info['show back'] = TRUE;
 184      }
 185  
 186      // Ensure these do not get out of sync.
 187      $form_state['item']->settings['name'] = $form_state['item']->name;
 188      $form_state['settings'] = $form_state['item']->settings;
 189  
 190      // Figure out the base style plugin in use and make sure that is available.
 191      $plugin = NULL;
 192      if (!empty($form_state['item']->settings['style_base'])) {
 193        $plugin = ctools_get_style_base($form_state['item']->settings['style_base']);
 194        ctools_stylizer_add_plugin_forms($form_info, $plugin, $form_state['op']);
 195      }
 196      else {
 197        // This is here so the 'finish' button does not show up, and because
 198        // we don't have the selected style we don't know what the next form(s)
 199        // will be.
 200        $form_info['order']['next'] = t('Configure style');
 201  
 202      }
 203  
 204      // If available, make sure these are available for the 'choose' form.
 205      if (!empty($form_state['item']->style_module)) {
 206        $form_state['module'] = $form_state['item']->style_module;
 207        $form_state['type'] = $form_state['item']->style_type;
 208      }
 209  
 210      $form_state['plugin'] = $plugin;
 211      $form_state['settings'] = $form_state['item']->settings;
 212      return $form_info;
 213    }
 214  
 215    /**
 216     * Store the stylizer info in our settings.
 217     *
 218     * The stylizer wizard stores its stuff in slightly different places, so
 219     * we have to find it and move it to the right place.
 220     */
 221    function store_stylizer_info(&$form_state) {
 222      /*
 223      foreach (array('name', 'admin_title', 'admin_description') as $key) {
 224        if (!empty($form_state['values'][$key])) {
 225          $form_state['item']->{$key} = $form_state['values'][$key];
 226        }
 227      }
 228      */
 229  
 230      if ($form_state['step'] != 'import') {
 231        $form_state['item']->settings = $form_state['settings'];
 232      }
 233      // Do not let the 'name' accidentally get out of sync under any circumstances.
 234      $form_state['item']->settings['name'] = $form_state['item']->name;
 235    }
 236  
 237    function edit_wizard_next(&$form_state) {
 238      $this->store_stylizer_info($form_state);
 239      parent::edit_wizard_next($form_state);
 240    }
 241  
 242    function edit_wizard_finish(&$form_state) {
 243      // These might be stored by the stylizer wizard, so we should clear them.
 244      if (isset($form_state['settings']['old_settings'])) {
 245        unset($form_state['settings']['old_settings']);
 246      }
 247      $this->store_stylizer_info($form_state);
 248      parent::edit_wizard_finish($form_state);
 249    }
 250  
 251    function edit_form_type(&$form, &$form_state) {
 252      foreach ($this->base_types as $module => $info) {
 253        foreach ($info as $key => $base_type) {
 254          $types[$module . '-' . $key] = $base_type['title'];
 255        }
 256      }
 257  
 258      $form['type'] = array(
 259        '#type' => 'select',
 260        '#title' => t('Type'),
 261        '#options' => $types,
 262        '#default_value' => 'all',
 263        '#weight' => -10,
 264        '#attributes' => array('class' => 'ctools-auto-submit'),
 265      );
 266    }
 267  
 268    function edit_form_type_submit(&$form, &$form_state) {
 269      list($form_state['item']->style_module, $form_state['item']->style_type) = explode('-', $form_state['values']['type']);
 270    }
 271  }


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