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 10 Jun 2010 08:29:09 -0000 @@ -16,6 +16,8 @@ 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' => 'none'); + $options['subject_link_custom'] = array('default' => ''); return $options; } @@ -50,6 +52,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 == 'display') { + $subject_link_display = $this->get_option('subject_link_display'); + if ($subject_link_display = $this->get_link_display()) { + $this_display = $this->display->id; + $this->view->set_display($subject_link_display); + // Add the link to the display if the user has access to it: + 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 == '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 +120,30 @@ class views_plugin_display_block extends 'title' => t('Caching'), 'value' => $types[$this->get_cache_type()], ); + + $subject_link_type = $this->get_option('subject_link_type'); + + if ($subject_link_type == 'custom') { + $subject_link = t('Custom path'); + } + elseif (($subject_link_type == 'display') && isset($this->view->display[$this->get_link_display()])) { + $subject_link = t('Display: @display_name', array('@display_name' => $this->view->display[$this->get_link_display()]->display_title)); + } + else { + $subject_link = t('No link'); + } + + // 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,6 +199,33 @@ class views_plugin_display_block extends '#default_value' => $this->get_cache_type(), ); break; + case 'subject_link_type': + $form['#title'] .= t('Title link'); + + $options = array( + 'none' => t('No link'), + 'display' => t("Link to the 'link display'"), + '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, + ); + + $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('custom'), + ), + ); + break; } } @@ -167,6 +244,10 @@ 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', $form_state['values']['subject_link_type']); + $this->set_option('subject_link_custom', trim($form_state['values']['subject_link_custom'])); + break; } } @@ -180,9 +261,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) {