Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion includes/views/handlers/message_handler_field_message_render.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
class message_handler_field_message_render extends views_handler_field {

// Message entities
var $messages = array();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid this $messages - as we end up caching this inside message_load and here. Instead - you can do something like:

function pre_render() {

...
+    if (empty($mids)) {
        // No Message IDs.
        return;
     }
     
    // Load the Messages in a single call, so they will be statically cached in the ::render function.
     message_load_multiple($mids);
}

Then, the render function will stay as-is, the message_load will however fetch the $message from the static cache.


/**
* Set default field name to render.
*/
Expand Down Expand Up @@ -70,14 +73,32 @@ class message_handler_field_message_render extends views_handler_field {
parent::options_form($form, $form_state);
}

function pre_render(&$values) {
$mids = array();
$field_alias = $this->field_alias;

foreach ($values as $value) {
if (!empty($value->{$field_alias})) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this be empty?

$mids[] = $value->{$field_alias};
}
}

if (!empty($mids)) {
$this->messages = message_load_multiple($mids);
}
}

function render($values) {
$field_alias = $this->field_alias;
if (!empty($values->{$field_alias}) && $message = message_load($values->{$field_alias})) {

if (!empty($values->{$field_alias}) && isset($this->messages[$values->{$field_alias}])) {
$message = $this->messages[$values->{$field_alias}];
$options = array(
'field name' => $this->options['field_name'],
'partials' => $this->options['partials'],
'partial delta' => $this->options['partials_delta'],
);

return $message->getText(NULL, $options);
}
}
Expand Down