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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 669636.patch | 3.31 KB | bojanz |
| #8 | 669636.patch | 20.07 KB | bojanz |
| #7 | 669636-refactor-links-7.patch | 20.08 KB | dawehner |
| #5 | 669636-refactor-links.patch | 20.14 KB | dawehner |
| #2 | 669636-refactor-links.patch | 20 KB | dawehner |
Comments
Comment #1
dawehnerAssign this to me
Comment #2
dawehnerComment #3
dawehnerUpdate
Comment #4
dagmarThis patch doesn't apply anymore.
Comment #5
dawehnerHere is a rerole
Comment #6
bojanz commentedThe 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)
Comment #7
dawehnerha.
After reading the patch:
Comment #8
bojanz commentedI 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.
Comment #9
merlinofchaos commentedThis *almost* applies to D7, there's only one failure, so this should be one of the easier ports.
Comment #10
dawehnerPorted the two remaining problems and commited.
Comment #11
bojanz commentednode_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.
Comment #12
bojanz commentedSo, 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...)
Comment #13
bojanz commentedNeeds to be committed to 6.x-3.x first.
Comment #14
Letharion commentedComment #15
dawehnerLooks fine.
Comment #16
merlinofchaos commentedApplied to 6.x-3.x and 7.x-3.x
Comment #18
sammyman commentedDo 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.
Comment #19
bojanz commentedYes, 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.