2

I have a "press release" node type which uses entityreference to link to any number of file_entity images, another field for file_entity videos and another to file_entity audio files.

There is a need for a block to display the first six images from the most recent press release, with some text from the press release.

So I built a view that finds the most recent press release and then displays the first six image entities. Or it should have but it doesn't, it always reports zero images (or zero videos, or zero audio files) regardless of how many there are.

So I ripped into Views to find the problem and discovered that entityreference does not provide a field handler, as a result Views assumes it's referring to a node and not an image and it all goes pear-shaped.

All entityreference does is provide a relationship handler, which is fine as far as it goes but you can only display one entry from the list of references - the first one.

Am I really going to go completely non-intuitive and have the images as the main table, and then sort by and group by parent press release node?

Any better ideas? (Short of writing a proper Views field handler?)

1

I think you will need to create a view of image entities, rather than nodes. The use a reverse relationship with the node that references it as a filter.

  • I've just been trying that but there's a problem (of course), the number of images on a press release is not a fixed and known number. And you can't limit the number of parent press releases, which means that if the press release only has one image you can't stop the images from the next press release appearing. Plus, the body text of the parent press release appears as many times as there are images. Aaargh. – Adaddinsane May 22 '12 at 16:31
  • The alternative is to output the press release node, use the rendered entity formatter, then put some logic in a preprocess function/template that says if it is displaying in a specific view, to just display the images. – Lomax May 23 '12 at 8:09
0

The real solution is a proper field handler, but I don't have time to implement that in my current contract so I'll just bypass the problem:

Create a block that can be configured with a specific entry (or chooses the latest) and hard code the display to be what's required.

That's the way it goes.

0

You can use the Content Dependency module. It provides you references via tab and supports following modules: node reference / entity reference.

Here is an excerpt about it from the module's project page:

Provides ability to view reversed referrals/references for content of entity reference & references - node_reference modules, etc.

Generally, this project enables content authors to see from any current content (entity) its dependent entities content.

Project overcome a major content control difficulty for content authors.

Provide content authors ability to track external content which refers to current content, without the need to check mass of external content to find out whether each external content refers to current content or not.

  • Can this module be used with a view? This question is specifically about a view. – kiamlaluno May 14 '13 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.