0

My Setup:

I am using Drupal 7.41 and Views / Views UI 3.11.

  1. I have a taxonomy named sermon series that includes a field called series image.
  2. I have a content type called sermons that has an image called sermon image and a term reference to the sermon series taxonomy.
  3. Lastly, I have a View called sermons that:
    • pulls in the most recent 1 node from the content type sermons
    • has a relationship to the taxonomy sermon series
    • has the first field in the fields list as the sermon series image (from taxonomy) and is set to "hide from display". The replacement pattern token for this field is [field_sermon_image_2]
    • has the second field in the fields list as the sermon image (from content type) and is set to show in the display.
      • this field has a no results behavior set to the token [field_sermon_image_2]

Expected Behavior:

If the most recent node has an image associated with it, that image will show. If there is no image associated with the node, it will show the image associated with the taxonomy sermon series.

Actual Behavior

When I create a node with the sermon image filled out, everything works as expected and the view shows the sermon image associated with the Node shows.

When I create a node without a sermon image filled out, the view correctly shows the sermon series image associated with the taxonomy sermon series.

Here's where it gets weird. If I create a node without a sermon image filled out, see the view correctly show the sermon series image from the taxonomy, then either clear cache or wait until cache expires, no image shows up at all. I know the fallback is working correctly as even the [field_sermon_image_2] has a no results behavior fallback to a generic image and that's what always shows up.

Through some testing, I found that unpublishing the node, viewing the view, then re-publishing the node will bring the correct image back (at least until the next cache flush).

I'm not sure where to look for this odd behavior. It seems like I have everything setup correctly in my view as I can get the correct images to show up, I just can't get them to show up consistently.

Any advice you can give would be appreciated. Thanks!

4
  • 1
    Does this happen when you are login as Admin or is this only for anonymous users? – No Sssweat Nov 6 '15 at 0:02
  • @no-sssweat in testing, it seems that roles don't play a part whether it's administrator or anonymous that initiates the cache. – Cory Fischer Nov 6 '15 at 3:19
  • 1
    If you inspect the element with your browser where the image is suppose to be does it show anything? – No Sssweat Nov 6 '15 at 5:14
  • No, it's empty. I've tested that by setting a fallback image for the "sermon series image" it falls back to that so there are three levels: Sermon Image --> Sermon Series Image ---> Default Image. Where I expect "sermon series image" to show up, the default image shows. – Cory Fischer Nov 7 '15 at 3:41
0

I replicated your scenario and its working fine for me.

Here is what I did.

  1. In Taxonomy I added a Vocabulary called "Sermons", I added an image field called "tax image"

  2. I added a term name of "Mega Man" to Sermons, and uploaded a mega man picture to the "tax image" field.

  3. Created an Article with title of "Enter Shikari is awesome" which has "Article Picture" as a field and I uploaded a picture of the band. Term Ref "Mega Man"

  4. I Created another Article with title "Woooo" this time I did not upload any image to the "Article Picture" field. Term Ref "Mega Man"

Now in Views

  1. In FILTER CRITERIA I added Content Type Is one of Article (so it only shows Article nodes)

  2. In RELATIONSHIP I added Content: Taxonomy terms on node

    • Check marked "Sermon Series"
    • Check marked Require this relationship.

enter image description here

  1. In FIELDS and I added the "tax image"

    • checked exclude from display.
  2. In FIELDS I added "Article Picture"

    • No Results behaviour I put the token [field_tax_image]

enter image description here

  1. I put a cache of 1 hour.

So here is what my View looks like

enter image description here

  1. I added another Article with title "Kewl its working!!!" with Term Ref "Mega Man" and left the "Article Picture" field empty.

  2. I Cleared the cache (since my view is cached, it won't show "kewl is working!!! until I clear it).

RESULT AS EXPECTED Kewl its working!!! and Wooo do not have Article Pictures, so Mega Man (tax image) shows up.

enter image description here

3
  • Thank you for the detailed answer! I have spent the last 3 hours comparing yours to mine, recreating mine to match yours & the only difference was making relationship required was missing on mine. Unfortunately my results are now all over the board. Saving, un/publishing, republishing yields completely different and unpredictable results. Sometimes it works sometimes it doesn't. Sometimes it works 20 times in a row, sometimes it breaks 20 times in a row. Other times it's 1 here or 2 there. I'm going to keep trying and I'll let you know what I find but wanted to thank you for your response! – Cory Fischer Nov 7 '15 at 8:21
  • making relationship required only shows Articles that have a term ref. If you still want to show Articles that don't have a term ref, then uncheck require box. Just know that if you then create an Article with no image and no term ref, then the view would not show an image because it doesn't have anything to work with (no article pic, no term ref). – No Sssweat Nov 7 '15 at 8:57
  • When you create a view by default FILTER CRITERIA has Content Published (Yes). So if you unpublished a node, it will not show up in the view. If you want unpublished nodes to show up you need to REMOVE Content Published (Yes) – No Sssweat Nov 7 '15 at 9:09

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.