[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/views/plugins/ -> views_plugin_display_block.inc (source)

   1  <?php
   2  // $Id: views_plugin_display_block.inc,v 1.5 2009/06/26 00:23:42 merlinofchaos Exp $
   3  /**
   4   * @file
   5   * Contains the block display plugin.
   6   */
   7  
   8  /**
   9   * The plugin that handles a block.
  10   *
  11   * @ingroup views_display_plugins
  12   */
  13  class views_plugin_display_block extends views_plugin_display {
  14    function option_definition() {
  15      $options = parent::option_definition();
  16  
  17      $options['block_description'] = array('default' => '', 'translatable' => TRUE);
  18      $options['block_caching'] = array('default' => BLOCK_NO_CACHE);
  19  
  20      return $options;
  21    }
  22  
  23    /**
  24     * The default block handler doesn't support configurable items,
  25     * but extended block handlers might be able to do interesting
  26     * stuff with it.
  27     */
  28    function execute_hook_block($op = 'list', $delta = 0, $edit = array()) {
  29      if ($op == 'list') {
  30        $delta = $this->view->name . '-' . $this->display->id;
  31        $desc = $this->get_option('block_description');
  32  
  33        if (empty($desc)) {
  34          $desc = t('@view: @display', array('@view' => $this->view->name, '@display' => $this->display->display_title));
  35        }
  36        return array(
  37          $delta => array(
  38            'info' => $desc,
  39            'cache' => $this->get_cache_type()
  40          )
  41        );
  42      }
  43    }
  44  
  45    /**
  46     * The display block handler returns the structure necessary for a block.
  47     */
  48    function execute() {
  49      // Prior to this being called, the $view should already be set to this
  50      // display, and arguments should be set on the view.
  51      $info['content'] = $this->view->render();
  52      $info['subject'] = filter_xss_admin($this->view->get_title());
  53      if (!empty($this->view->result) || $this->get_option('empty') || !empty($this->view->style_plugin->definition['even empty'])) {
  54        return $info;
  55      }
  56    }
  57  
  58    /**
  59     * Provide the summary for page options in the views UI.
  60     *
  61     * This output is returned as an array.
  62     */
  63    function options_summary(&$categories, &$options) {
  64      // It is very important to call the parent function here:
  65      parent::options_summary($categories, $options);
  66  
  67      $categories['block'] = array(
  68        'title' => t('Block settings'),
  69      );
  70  
  71      $block_description = strip_tags($this->get_option('block_description'));
  72      if (empty($block_description)) {
  73        $block_description = t('None');
  74      }
  75  
  76      if (strlen($block_description) > 16) {
  77        $block_description = substr($block_description, 0, 16) . '...';
  78      }
  79  
  80      $options['block_description'] = array(
  81        'category' => 'block',
  82        'title' => t('Admin'),
  83        'value' => $block_description,
  84      );
  85  
  86      $cache_type = $this->get_option('block_caching');
  87      if (empty($cache_type)) {
  88        $cache_type = BLOCK_NO_CACHE;
  89      }
  90  
  91      $types = $this->block_caching_modes();
  92      $options['block_caching'] = array(
  93        'category' => 'block',
  94        'title' => t('Caching'),
  95        'value' => $types[$this->get_cache_type()],
  96      );
  97    }
  98  
  99    /**
 100     * Provide a list of core's block caching modes.
 101     */
 102    function block_caching_modes() {
 103      return array(
 104        BLOCK_NO_CACHE => t('Do not cache'),
 105        BLOCK_CACHE_GLOBAL => t('Cache once for everything (global)'),
 106        BLOCK_CACHE_PER_PAGE => t('Per page'),
 107        BLOCK_CACHE_PER_ROLE => t('Per role'),
 108        BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE => t('Per role per page'),
 109        BLOCK_CACHE_PER_USER => t('Per user'),
 110        BLOCK_CACHE_PER_USER | BLOCK_CACHE_PER_PAGE => t('Per user per page'),
 111      );
 112    }
 113  
 114    /**
 115     * Provide a single method to figure caching type, keeping a sensible default
 116     * for when it's unset.
 117     */
 118    function get_cache_type() {
 119      $cache_type = $this->get_option('block_caching');
 120      if (empty($cache_type)) {
 121        $cache_type = BLOCK_NO_CACHE;
 122      }
 123      return $cache_type;
 124    }
 125  
 126    /**
 127     * Provide the default form for setting options.
 128     */
 129    function options_form(&$form, &$form_state) {
 130      // It is very important to call the parent function here:
 131      parent::options_form($form, $form_state);
 132  
 133      switch ($form_state['section']) {
 134        case 'block_description':
 135          $form['#title'] .= t('Block admin description');
 136          $form['block_description'] = array(
 137            '#type' => 'textfield',
 138            '#description' => t('This will appear as the name of this block in administer >> site building >> blocks.'),
 139            '#default_value' => $this->get_option('block_description'),
 140          );
 141          break;
 142        case 'block_caching':
 143          $form['#title'] .= t('Block caching type');
 144  
 145          $form['block_caching'] = array(
 146            '#type' => 'radios',
 147            '#description' => t("This sets the default status for Drupal's built-in block caching method; this requires that caching be turned on in block administration, and be careful because you have little control over when this cache is flushed."),
 148            '#options' => $this->block_caching_modes(),
 149            '#default_value' => $this->get_cache_type(),
 150          );
 151          break;
 152      }
 153    }
 154  
 155    /**
 156     * Perform any necessary changes to the form values prior to storage.
 157     * There is no need for this function to actually store the data.
 158     */
 159    function options_submit(&$form, &$form_state) {
 160      // It is very important to call the parent function here:
 161      parent::options_submit($form, $form_state);
 162      switch ($form_state['section']) {
 163        case 'block_description':
 164          $this->set_option('block_description', $form_state['values']['block_description']);
 165          break;
 166        case 'block_caching':
 167          $this->set_option('block_caching', $form_state['values']['block_caching']);
 168          $this->save_block_cache($form_state['view']->name.'-'.$form_state['display_id'], $form_state['values']['block_caching']);
 169          break;
 170      }
 171    }
 172  
 173    /**
 174     * Block views use exposed widgets only if AJAX is set.
 175     */
 176    function uses_exposed() {
 177      if ($this->use_ajax()) {
 178        return parent::uses_exposed();
 179      }
 180  
 181      return FALSE;
 182    }
 183    
 184    /**
 185     * Save the block cache setting in the blocks table if this block allready 
 186     * exists in the blocks table. Dirty fix untill http://drupal.org/node/235673 gets in.
 187     */
 188    function save_block_cache($delta, $cache_setting) {
 189      if ($bid = db_fetch_object(db_query("SELECT bid, cache FROM {blocks} WHERE module = 'views' AND delta = '%s'", $delta))) {
 190        db_query("UPDATE {blocks} set cache = %d WHERE module = 'views' AND delta = '%s'", $cache_setting, $delta);
 191      }
 192    }
 193  }


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