I want to display the "masquerade as" link provided by Masquerade Extras in the contextual module, using the Contextual Links global field provided by Views.

The link adds a token query parameter to prevent XSS attacks. This parameter is set in $this->view->field[$field]->options['alter']['query'], which is completely ignored by views_handler_field_contextual_links.

I will post a patch.

Comments

Jorrit’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB

The attached patch fixes the problem and slightly improves performance by calculating the 'destination' parameter just once.

chris matthews’s picture

Version: 7.x-3.5 » 7.x-3.x-dev
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 6 year old patch to views_handler_field_contextual_links.inc does not apply to the latest views 7.x-3.x-dev and if still applicable needs to be rerolled.

Checking patch handlers/views_handler_field_contextual_links.inc...
error: while searching for:
   */
  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();
        }
      }
    }

error: patch failed: handlers/views_handler_field_contextual_links.inc:55
error: handlers/views_handler_field_contextual_links.inc: patch does not apply
Jorrit’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.48 KB

Rerolled

chris matthews’s picture

The rerolled patch in #3 to views_handler_field_links.inc applied cleanly and fixes this issue for me.