Index: plugins/views_plugin_display_block.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_display_block.inc,v retrieving revision 1.5 diff -u -p -r1.5 views_plugin_display_block.inc --- plugins/views_plugin_display_block.inc 26 Jun 2009 00:23:42 -0000 1.5 +++ plugins/views_plugin_display_block.inc 28 Oct 2009 07:32:13 -0000 @@ -5,6 +5,10 @@ * Contains the block display plugin. */ +define('VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_NONE', 1); +define('VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_DISPLAY', 2); +define('VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_CUSTOM', 3); + /** * The plugin that handles a block. * @@ -16,6 +20,9 @@ class views_plugin_display_block extends $options['block_description'] = array('default' => '', 'translatable' => TRUE); $options['block_caching'] = array('default' => BLOCK_NO_CACHE); + $options['subject_link_type'] = array('default' => VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_NONE); + $options['subject_link_display'] = array('default' => ''); + $options['subject_link_custom'] = array('default' => ''); return $options; } @@ -50,6 +57,30 @@ class views_plugin_display_block extends // display, and arguments should be set on the view. $info['content'] = $this->view->render(); $info['subject'] = filter_xss_admin($this->view->get_title()); + + // Now check to see if we have a link to add to the title: + $subject_link_type = $this->get_option('subject_link_type'); + if ($subject_link_type == VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_DISPLAY) { + $displays = $this->_get_displays_with_path($this->view); + $subject_link_display = $this->get_option('subject_link_display'); + if (isset($displays[$subject_link_display])) { + $this_display = $this->display->id; + $this->view->set_display($subject_link_display); + if ($this->view->access($subject_link_display)) { + $info['subject'] = l($info['subject'], $this->view->get_url(), array('html' => TRUE)); + } + $this->view->set_display($this_display); + } + } + elseif ($subject_link_type == VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_CUSTOM) { + $link_url = $this->get_option('subject_link_custom'); + $args = array_values($this->view->args); + foreach ($args as $key => $a) { + $link_url = str_replace('%' . ($key + 1), $a, $link_url); + } + $info['subject'] = l($info['subject'], $link_url, array('html' => TRUE)); + } + if (!empty($this->view->result) || $this->get_option('empty') || !empty($this->view->style_plugin->definition['even empty'])) { return $info; } @@ -94,6 +125,34 @@ class views_plugin_display_block extends 'title' => t('Caching'), 'value' => $types[$this->get_cache_type()], ); + + $subject_link_type = $this->get_option('subject_link_type'); + $subject_link_display = $this->get_option('subject_link_display'); + + if (empty($subject_link_type) || $subject_link_type == VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_NONE) { + $subject_link = t('No link'); + } + elseif ($subject_link_type == VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_CUSTOM) { + $subject_link = t('Custom path'); + } + else { + $displays = $this->_get_displays_with_path($this->view); + if (isset($displays[$subject_link_display])) { + $subject_link = t('Display: @display', array('@display' => $displays[$subject_link_display])); + } + } + + // Trim a long display name: + if (strlen($subject_link) > 18) { + $subject_link = substr($subject_link, 0, 15) .'...'; + } + + + $options['subject_link_type'] = array( + 'category' => 'block', + 'title' => t('Title link'), + 'value' => $subject_link, + ); } /** @@ -149,10 +208,69 @@ class views_plugin_display_block extends '#default_value' => $this->get_cache_type(), ); break; + case 'subject_link_type': + $form['#title'] .= t('Title link'); + + $options = array( + VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_NONE => t('No link'), + VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_DISPLAY => t('Link to a page display'), + VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_CUSTOM => t('Link to a custom path'), + ); + $form['subject_link_type'] = array( + '#type' => 'radios', + '#description' => t('Select if the block\'s title should be a link.'), + '#default_value' => $this->get_option('subject_link_type'), + '#options' => $options, + ); + + $options = $this->_get_displays_with_path($this->view); + $form['subject_link_display'] = array( + '#type' => 'select', + '#title' => t('Linked display'), + '#description' => t("Select another display to link this block's title to."), + '#default_value' => $this->get_option('subject_link_display'), + '#options' => $options, + // Only show if the user has selected the 'display' type above: + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:subject_link_type' => array(VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_DISPLAY), + ), + ); + + $form['subject_link_custom'] = array( + '#type' => 'textfield', + '#title' => t('Custom link'), + '#description' => t("Enter a custom URL to link this block's title to. Use %1, %2, etc. to be replaced with view arguments."), + '#default_value' => $this->get_option('subject_link_custom'), + // Only show if the user has selected the 'custom' type above: + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:subject_link_type' => array(VIEWS_PLUGIN_DISPLAY_BLOCK_TITLE_LINK_CUSTOM), + ), + ); + break; } } /** + * Return an array of displays of the given view that 'live' at a path. + * + * Currently this function doesn't really work. + * TODO: Fix it. + */ + function _get_displays_with_path($view) { + $displays = array(); + foreach ($view->display as $display) { + $view->set_display($display->id); + $path = $view->get_path(); + if (!empty($path)) { + $displays[$display->id] = $display->display_title; + } + } + return $displays; + } + + /** * Perform any necessary changes to the form values prior to storage. * There is no need for this function to actually store the data. */ @@ -167,6 +285,11 @@ class views_plugin_display_block extends $this->set_option('block_caching', $form_state['values']['block_caching']); $this->save_block_cache($form_state['view']->name.'-'.$form_state['display_id'], $form_state['values']['block_caching']); break; + case 'subject_link_type': + $this->set_option('subject_link_type', trim($form_state['values']['subject_link_type'])); + $this->set_option('subject_link_display', trim($form_state['values']['subject_link_display'])); + $this->set_option('subject_link_custom', trim($form_state['values']['subject_link_custom'])); + break; } } @@ -180,9 +303,9 @@ class views_plugin_display_block extends return FALSE; } - + /** - * Save the block cache setting in the blocks table if this block allready + * Save the block cache setting in the blocks table if this block allready * exists in the blocks table. Dirty fix untill http://drupal.org/node/235673 gets in. */ function save_block_cache($delta, $cache_setting) {