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

Deciphered’s picture

Status: Active » Fixed

Hi,

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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jonathan_hunt’s picture

Status: Closed (fixed) » Active

I'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.

$result = array();
$result = entityreference_field_formatter_view($variables['#obj_type'], $variables['#object'], $variables['#field'], $variables['#instance'], $variables['#langcode'], $variables['#items'], $variables['#display']);
return $result;

But in preview I get:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /system/ajax
StatusText: Service unavailable (with message)
ResponseText: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7540 of /Sites/drupal-7.14/includes/common.inc).
Deciphered’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Issue summary: View changes
Status: Active » Fixed

While 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

NWOM’s picture

Category: Support request » Feature request
Status: Closed (fixed) » Active

Is this a possibility now, now that the Field tokens module is available, unlike 4 years ago?

bisonbleu’s picture

I 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.