Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Guess you created a custom field hander and would like provide some additional options for "Output this field as a link" (i.e. adding an attribute). Currently you will have to copy the function render_as_link()
and make your modifications.
Proposed resolution
Add a possibility to alter the link parameters directly before passing it to the l()
-function.
Remaining tasks
User interface changes
None.
API changes
New function alter_render_as_link(&$text, &$path, &$options, array $context) { }
in views_handler_field.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#6 | views-make_render_as_link_in_views_handler_field-2580139-6.patch | 1.35 KB | Andrew Answer |
|
Comments
Comment #2
stBorchertPatch introduces the new function.
Example usage in custom field handler class:
Comment #3
drupalove CreditAttribution: drupalove as a volunteer commentedIs it useful to have this in Drupal 8? If yes, will the backport policy apply?
Comment #4
stBorchertYes, this may apply to Drupal 8, too.
But: after looking at FieldPluginBase::renderAsLink() I guess one can simply override the renderer used for the custom field handler and inject the modifications into the render-array.
Comment #5
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 3 year old patch in #2 to views_handler_field.inc does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.
Comment #6
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.