I'm working on a video-page using two Content types, Score and Video. In Video I use a file-field with multiple numbers of values, to upload m4v-, ogv- and png-files using the videoJs-plugin to render it nicely in html5.
The Score content type has an entity-reference-field to select some of the video-nodes. Everything works fine. I get score-nodes with the referenced videos included. But the format-options don't sute what I want. I only can render them as full video or as a label with link to the video-node. I want to have the poster-images with a colorbox-link to the video-node.
So I installed Custom Formatters, but can't figure out how to get the poster-image-url. I tried the HTML + Tokens way, but the only Entity Reference field is [node:field_scorevideos], and this renders the complete video. So I changed to PHP-Editor, but I'm stuck due to lacking knowledge. I've installed Devel and I can see the $variables, but it only shows me target_id of the video-node.
Can s.o. put me on the right track? Every help is appreciated!
Comments
Comment #1
Deciphered CreditAttribution: Deciphered commentedHi,
Unfortunately Field tokens in Drupal 7 is currently lacking, so the PHP option is the better choice.
To get the referenced entity you will need to load it from the target_id with either the entity_load() function or the entityreference_field_load() function.
If you have more specifics I may be able to help you out a bit more.
Cheers,
Deciphered.
Comment #3
jonathan_hunt CreditAttribution: jonathan_hunt commentedI'm working on something similar, simply to get a comma-separated list of linked entity labels.
I tried calling the default formatter first, so I can then work with the output.
But in preview I get:
Comment #4
Deciphered CreditAttribution: Deciphered commentedWhile I didn't get the error you are getting, I didn't get a result either, and that is because you need to adjust the values of
$variables['#display']
before you pass it through to the originally formatter.Comment #6
NWOM CreditAttribution: NWOM commentedIs this a possibility now, now that the Field tokens module is available, unlike 4 years ago?
Comment #7
bisonbleu CreditAttribution: bisonbleu commentedI have the same question.
My use case is to inject CSS classes in the 'a' tag to transform the entityreference's plain link into a button. So what I'm trying to achieve is to replace the default markup wwith this:
<a class="button button-go-back" href="/node/[node:field-entityreference:0:target-id]">Go back to referenced node</a>
But it's not working. Either my token is wrong or this isn't possible.
Fortunately I was able to achieve the desired result with the custom_formatters php format.