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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stBorchert created an issue. See original summary.

stBorchert’s picture

Status: Active » Needs review
FileSize
1.33 KB

Patch introduces the new function.

Example usage in custom field handler class:

<?php
function alter_render_as_link(&$text, &$path, &$options, array $context) {
  $id = strtr($context['alter']['link_id'], $context['tokens']);
  if ($id) {
    $options['attributes']['id'] = array($id);
  }
}
?>
drupalove’s picture

Is it useful to have this in Drupal 8? If yes, will the backport policy apply?

stBorchert’s picture

Yes, 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.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 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.

Checking patch handlers/views_handler_field.inc...
Hunk #1 succeeded at 1396 (offset 33 lines).
error: while searching for:
  }

  /**
   * Get the 'render' tokens to use for advanced rendering.
   *
   * This runs through all of the fields and arguments that

error: patch failed: handlers/views_handler_field.inc:1373
error: handlers/views_handler_field.inc: patch does not apply
Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.35 KB

Patch rerolled.