0

I have a view (using the calendar module), which displays a title field for each displayed event. The title field is set to "link this field to the original piece of content".

I'd like to rewrite that link to add some additional parameters, e.g. ?return_view=myview, so that I can link back to the view page from the content. The content might be linked to from any one of several different views, so it needs to take some parameter (i.e. return_view) to tell it what to link back to.

I've tried adding a hook_views_pre_render:

function mymodule_views_pre_render(&$view) {
    if ($view->name == 'myview') {
        foreach ($view->result as &$r) {
            $r->node_title = array(
                '#theme' => 'link',
                '#text' => 'xyz',
                '#path' => 'node/' . 123,
                '#options' => array(
                    'query' => array(
                        'rv' => $view->name,
                        'rvd' => $view->current_display
                    ),
                    'attributes' => array(),
                    'html' => FALSE
                )
            );
        }
    }
}

But that just leads to Drupal complaining that "warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain()" - I'm assuming because some rendering function somewhere expects to get a plain string.

What's the cleanest way to add additional query parameters to a node title rendered by views?

1 Answer 1

1

You can do this in Views.

  1. Add a new field to the View "Content: Path".
  2. Check Exclude from display.
  3. Click on Rewrite Results and the check "Use absolute link".
  4. Click Apply button to Save.
  5. Rearrange your fields so "Content: Path" is above "Content: Title".
  6. Click on the "Content: Title" field.
  7. Uncheck "Link this field to the original piece of content".
  8. Click on Rewrite Results and check "Output this field as a link".
  9. In the Link path textbox enter "[path]?return_view=myview". (You can use the path replacement pattern because it is above the title field in the field order)
  10. Click Apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.