The handler views_filed_handler contains a function called render_as_link that is fired when $options['alter']['path'] is not empty.

Handlers can use render_link to alter the options of options_definition in order to render the field as a link.

Several handlers that currently displays links should be modified to support this feature, as far I know this handler should be modified:

modules/user/views_handler_field_user_mail.inc
modules/user/views_handler_field_user_link.inc
modules/user/views_handler_field_user_link_edit.inc
modules/user/views_handler_field_user_link_delete.inc
modules/aggregator/views_handler_field_aggregator_title_link.inc
modules/comment/views_handler_field_comment_link_edit.inc
modules/comment/views_handler_field_comment_link_reply.inc
modules/comment/views_handler_field_comment_link_delete.inc
modules/comment/views_handler_field_comment_link.inc
modules/node/views_plugin_row_node_rss.inc
modules/node/views_handler_field_node_revision_link_delete.inc
modules/node/views_handler_field_node_revision_link_revert.inc
modules/node/views_handler_field_node_link.inc
modules/node/views_handler_field_node_link_delete.inc
modules/node/views_handler_field_node_link_edit.inc
modules/statistics/views_handler_field_accesslog_path.inc
modules/contact/views_handler_field_contact_link.inc
modules/contact/views_handler_field_contact_link.inc
modules/translation/views_handler_field_node_translation_link.inc
modules/locale/views_handler_field_locale_link_edit.inc

A example to "how to do this" can be found in:

modules/user/views_handler_field_user.inc

  function render_link($data, $values) {
    if (!empty($this->options['link_to_user']) && user_access('access user profiles') && $values->{$this->aliases['uid']} && $data !== NULL && $data !== '') {
      $this->options['alter']['make_link'] = TRUE;
      $this->options['alter']['path'] = "user/" . $values->{$this->aliases['uid']};
    }
    return $data;
  }

This function only enable the 'make_link' and 'path' option. Also probably a lot of handlers will have to inherit from the views_handler_field.

Also, option_definition should be modified to include as deafult text the text for the link, i.e. for contact forms:

function option_definition() {
  $options = parent::option_definition();
  $options['text'] = array('default' => array('Contact form'), 'translatable' => TRUE));
  return $options;
}

One of the benefices of this job is that user would be able to modify the text of the links, using tokens, or specials class for links, etc.

Before start this hard task would be nice heard some opinions about this work. Specially how to mantain old values for links like "Delete comment" that would be modified by the a nid link if we doesn't perform some conversion tasks before.

Comments

dawehner’s picture

Assigned: Unassigned » dawehner

Assign this to me

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new20 KB
[x]modules/user/views_handler_field_user_mail.inc
[x]modules/user/views_handler_field_user_link.inc
[x]modules/user/views_handler_field_user_link_edit.inc
[x]modules/user/views_handler_field_user_link_delete.inc
[x]modules/aggregator/views_handler_field_aggregator_title_link.inc
[x]modules/comment/views_handler_field_comment_link_edit.inc
[x]modules/comment/views_handler_field_comment_link_reply.inc
[x]modules/comment/views_handler_field_comment_link_delete.inc
[x]modules/comment/views_handler_field_comment_link.inc
[-------]modules/node/views_plugin_row_node_rss.inc
[x]modules/node/views_handler_field_node_revision_link_delete.inc
[x]modules/node/views_handler_field_node_revision_link_revert.inc
[x]modules/node/views_handler_field_node_link.inc
[x]modules/node/views_handler_field_node_link_delete.inc
[x]modules/node/views_handler_field_node_link_edit.inc
[x]modules/statistics/views_handler_field_accesslog_path.inc
[x]modules/contact/views_handler_field_contact_link.inc
[x]modules/translation/views_handler_field_node_translation_link.inc
[x]modules/locale/views_handler_field_locale_link_edit.inc
dawehner’s picture

Issue tags: +alpha-4 blocker

Update

dagmar’s picture

Status: Needs review » Needs work

This patch doesn't apply anymore.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new20.14 KB

Here is a rerole

bojanz’s picture

Status: Needs review » Needs work
@@ -23,8 +23,12 @@ class views_handler_field_node_link_delete extends views_handler_field_node_link
       return;
     }
 
-    $text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
-    return l($text, "node/$node->nid/delete", array('query' => drupal_get_destination()));
+    $this->options['alter']['make_link'] = TRUE;
+    $this->options['alter']['path'] = "node/$node->nid/delete";
+    $this->options['alter']['query'] = drupal_get_destination();
+
+    $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
+    return $text;
   }
 }

The default label for the delete link should be "delete" and not "edit".

Also, I get no output for the Comment: Edit link, because the handler's render_link() function doesn't have "return $text;" at the end.

I think that's it. The patch is nice, the code looks good, and I've confirmed that every user link works as it should, same for the node/comment links (if we disregard the problems above).

Need to run now, will test everything (and reroll if dereine doesn't beat me to it) once I find the time again (next few days)

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new20.08 KB

ha.

After reading the patch:


+    $text = $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
bojanz’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new20.07 KB

I can't believe both of us missed that :)

The new patch is fine. I found a case of ";;" at the end of one line, and trailing whitespace on another line.
Attaching the patch with those two silly things fixed, and marking this as RTBC.

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

This *almost* applies to D7, there's only one failure, so this should be one of the easier ports.

dawehner’s picture

Status: Patch (to be ported) » Fixed

Ported the two remaining problems and commited.

bojanz’s picture

Assigned: dawehner » bojanz
Status: Fixed » Needs work

node_link is throwing errors in both D6 and D7.
Just marked #980756: Error when adding "Node: Link" field in views and #980628: Many notices in view as duplicate.

Preparing a patch.

bojanz’s picture

Status: Needs work » Needs review
StatusFileSize
new3.31 KB

So, what's the problem?
In some render() functions we are trying to access $values->{$this->field_alias} even though we overrode query(), which means that $this->field_alias is set to the default value ("unknown"), which is of course not present in the $values object.

Here's a patch fixing the problem for 6.x and 7.x.
If the query() method was overridden, pass something else as $data to render_link (we aren't using it anyway...)

bojanz’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev

Needs to be committed to 6.x-3.x first.

Letharion’s picture

Assigned: bojanz » merlinofchaos
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Applied to 6.x-3.x and 7.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sammyman’s picture

Do we have to use the patch attached to fix the problem in Drupal 7? Or is the newest version of Views include the fixed code? I have the newest version of Views and I am still having this error.

bojanz’s picture

Yes, the patch went into 7.x, as merlinofchaos said in #16.
Open a new issue for your problem, the bug behind the previous errors was fixed.