I have a view that is listing users and some fields (like fullname , etc. ) and i need the send message link. The module is providing such a handler to render the link and all if working great. Then i had request from the design to change it so i had to show only image and then in the label of the send message link to use tokens so i can show the full name in the label (as this is feature that the handler is claiming to provide). and thought that this should be ok however this does not work correctly. The result is that all labels get the last user fullname rendered. This is cause cause the label function of the field is invoked in template_preprocess_views_view_fields() that is way after all the rows are rendered so the call
$this->get_render_tokens($this);
will return the tokens for the last row. However there is a very simple way to get the tokens for the current row using this code
$tokens = !empty($this->view->style_plugin->render_tokens[$this->view->row_index]) ? $this->view->style_plugin->render_tokens[$this->view->row_index] : array();.
The style plugin is always storing the tokens for each row and when the field->label() is invoked the row index is clear. This way the token replacement is working correctly. Also when you are editing the view you will see the token in the label as well because it was removed before.
Hope this helps other people that might need token replacement in the label.

Kind Regards,
Dobromir

Comments

vflirt’s picture

Issue summary: View changes
ivnish’s picture

Status: Active » Closed (outdated)