The EntityMetadataWrapper should like most objects when converted to a string return a text version of the property and not the text "Property [name]"

This is a small change which will mean when using a wrapped object it will return what is expected.

is in the case of the following

echo $node->title;

should echo the node title, and not "Property title".

I have created a new module twig_filter http://drupal.org/sandbox/gordon/1991592 which adds an action to rules to filter a string with twig string and using the using all the available variables in rules.

So using the following

the node title is {{ node.title }} and the author is {{ node.author.name }}

will return "the node title is Test title 1 and the author is john.doe"

or with the power of twig

{% for node.taxonomy in term %}
{{ term.name }}
{% endfor %}

or for invoices in ecommerce

{% for txn.items in node %}
{{ node.qty }} of {{ node.title }} at {{ node.price }} each
{% endfor %}

I am hoping this small change will go in as it will make formating emails, and other text amazing.

Comments

gordon’s picture

bump

fago’s picture

Status: Needs review » Needs work

That's a neat use-case. I'm a bit hesitant to change that as it has to be stable, but on the other hand no one can rely on the current output of "Property .." really - it's for devs only.

So defaulting to the value should be fine, but we also have label() - shouldn't we use that when we have one? E.g., node.tag.0 would display the term name instead of the tid... ?

gordon’s picture

that sounds good, but as long as this is the functionality is similar to D8 just for consistency. I will take a look at this use case.