From fd675a37cb987aea6cd1c6c18cf334eb9ec557e8 Mon Sep 17 00:00:00 2001 From: solotandem Date: Wed, 22 Oct 2014 19:00:09 +0000 Subject: [PATCH] Issue #1608920: Add drop-button field handler with support for more URL options. --- handlers/views_handler_field_contextual_links.inc | 65 ++---------- handlers/views_handler_field_ctools_dropdown.inc | 55 ++++++++++ handlers/views_handler_field_links.inc | 117 +++++++++++++++++++++ modules/views.views.inc | 8 ++ views.info | 2 + 5 files changed, 191 insertions(+), 56 deletions(-) create mode 100644 handlers/views_handler_field_ctools_dropdown.inc create mode 100644 handlers/views_handler_field_links.inc diff --git a/handlers/views_handler_field_contextual_links.inc b/handlers/views_handler_field_contextual_links.inc index faeeedc..4386e05 100644 --- a/handlers/views_handler_field_contextual_links.inc +++ b/handlers/views_handler_field_contextual_links.inc @@ -10,35 +10,7 @@ * * @ingroup views_field_handlers */ -class views_handler_field_contextual_links extends views_handler_field { - function option_definition() { - $options = parent::option_definition(); - - $options['fields'] = array('default' => array()); - $options['destination'] = array('default' => TRUE, 'bool' => TRUE); - - return $options; - } - - function options_form(&$form, &$form_state) { - $all_fields = $this->view->display_handler->get_field_labels(); - // Offer to include only those fields that follow this one. - $field_options = array_slice($all_fields, 0, array_search($this->options['id'], array_keys($all_fields))); - $form['fields'] = array( - '#type' => 'checkboxes', - '#title' => t('Fields'), - '#description' => t('Fields to be included as contextual links.'), - '#options' => $field_options, - '#default_value' => $this->options['fields'], - ); - $form['destination'] = array( - '#type' => 'checkbox', - '#title' => t('Include destination'), - '#description' => t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.'), - '#default_value' => $this->options['destination'], - ); - } - +class views_handler_field_contextual_links extends views_handler_field_links { function pre_render(&$values) { // Add a row plugin css class for the contextual link. $class = 'contextual-links-region'; @@ -50,35 +22,18 @@ class views_handler_field_contextual_links extends views_handler_field { } } + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['fields']['#description'] = t('Fields to be included as contextual links.'); + $form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.'); + } + /** * Render the contextual fields. */ function render($values) { - $links = array(); - foreach ($this->options['fields'] as $field) { - if (empty($this->view->style_plugin->rendered_fields[$this->view->row_index][$field])) { - continue; - } - $title = $this->view->field[$field]->last_render_text; - $path = ''; - if (!empty($this->view->field[$field]->options['alter']['path'])) { - $path = $this->view->field[$field]->options['alter']['path']; - } - if (!empty($title) && !empty($path)) { - // Make sure that tokens are replaced for this paths as well. - $tokens = $this->get_render_tokens(array()); - $path = strip_tags(decode_entities(strtr($path, $tokens))); - - $links[$field] = array( - 'href' => $path, - 'title' => $title, - ); - if (!empty($this->options['destination'])) { - $links[$field]['query'] = drupal_get_destination(); - } - } - } - + $links = $this->get_links(); if (!empty($links)) { $build = array( '#prefix' => '