When using a Views argument based on an entityref field it would be useful to be able to use the entity label in the views title using argument title substitution.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Needs review
FileSize
2.09 KB

Here's a patch, modelled on the Views handlers for term arguments.

Status: Needs review » Needs work

The last submitted patch, 1588574.entityreference.views-argument-handler-title.patch, failed testing.

joachim’s picture

Status: Needs work » Needs review
FileSize
2.12 KB

Helps if I roll against HEAD...

Changed the handler class name to be consistent with views classes already there.

joachim’s picture

Damien Tournoud’s picture

Can you explain what this does? It's fairly not obvious.

+      // Load the entity and get its label.
+      $entity = entity_object_load($value, $entity_type);

This is the menu loader function... you want entity_load_single().

joachim’s picture

When you use a Views argument with a numeric value such as a taxonomy term tid, you can have the term's label in the title set by the argument.

Currently, with entref, you just get the ID.

joachim’s picture

FileSize
50.06 KB

This bit:

entref-views-arg-id.png

With a taxo term ref argument, %1 gets you the term label.
With an entref field, you get just the entity ID.

This patch fixes that.

joachim’s picture

rocketeerbkw’s picture

#8 is working for me when referencing Nodes or Users

amitaibu’s picture

+++ b/views/entityreference_handler_argument_target_id.incundefined
@@ -0,0 +1,30 @@
+    foreach ($this->value as $value) {
+      // Load the entity and get its label.
+      $entity = entity_load_single($entity_type, $value);

Can't we entity_load() all entities at-once?

joachim’s picture

Status: Needs review » Needs work

Yeah fair point.

juves’s picture

That's exactly what I need, thanks!

juves’s picture

FileSize
30.08 KB

Reference field as a context filter (as summary) in view-attachment is still shown as id

Screenshot

joachim’s picture

Status: Needs work » Needs review
FileSize
2.1 KB

Here's a patch with comment 10 addressed.

I'm not sure about comment 13. I suspect views summaries use something else in the argument handler to get the title?

jhedstrom’s picture

This looks good to me. Fixes an issue where the views_data_export module wasn't outputting the downloaded filename properly (entity ID instead of entity title, but with this patch, the title is properly output instead of the ID).