1

I have a URL for an event content type that concatenates two other content types, namely "name-of-venue" and "name-of-performer" with "date-of-event", so the url is "name-of-venue/name-of-performer/dateofevent".

I wish to place a block on the event content type that shows only the events for that venue.

I have tried to configure the contextual filter as shown on the screen shot,

contextual filter configuration

using the PHP code:

$np = explode('/', drupal_get_normal_path($argument)); if (!empty($np[3])) { $handler->argument = $np[3]; return TRUE; } else { return FALSE; }

However this does not return just those events for that specific venue, but for all venues.

Consequently I fear that I am not actually exploding the url and so failing to obtain the NID for "name-of-venue" that I need for the contextual filter.

Any suggestions would be very much appreciated.

Thank you.

11
  • Do you want to display the View Block on the Event Content Type? Or on the Venue Content Type? I am a bit confused by the "...I wish to place a block on the event content type that shows only the events for that venue...". I would expect sth like "...I wish to place a block on the Venue content type that shows only the events for that venue...". Cheers! Commented Apr 25, 2016 at 17:25
  • Apologies @StefanosPetrakis, I want to display the view block on the event content type that shows only the events for that venue.
    – Richard
    Commented Apr 26, 2016 at 14:50
  • So, you want a view that will display events related to the current event. The relation being "same venue". I hope I got this right this time. If I did, then the next question would be, why you would need code for validation? You could grab the NID from the internal node path (node/%nid) and use that further in your view to get all related events. I could give you an example of that, if I am on the right track. Cheers again! Commented Apr 26, 2016 at 15:40
  • @StefanosPetrakis. Correct! I think I've tried what you're suggesting, but obviously I must be doing something wrong. Any example would be very much appreciated. Many thanks for all your help.
    – Richard
    Commented Apr 26, 2016 at 15:43
  • Okey! And you are using Entiry Reference for the linkage between Events and Venues, right? Commented Apr 26, 2016 at 15:46

1 Answer 1

0

Here is a kind-of-complex sketch for your problem, using only Views:

  1. Create a block view displaying Content of type Event
  2. Add a "Content: Nid" contextual filter, using the default settings. You may need to set the default value to "Content ID from URL" for the case "When the filter value is NOT available"
  3. In your View configuration, under "Relationships", create a "Entity Reference: Referenced entity" relationship for your reference field (e.g. field_venue) and click on "Require this relationship": This relationship will retrieve the venue of the Event that is defined from the contextual filter.
  4. Create a second relationship, one of type "Entity Reference: Referencing entity", again for your reference field (e.g. field_venue) and click on "Require this relationship". Important: Use the first relationship (step 3) for this one: This second relationship will retrieve the events that reference the venue we got from the first relationship.
  5. Set your Views format to use fields (either by using a Table or by ticking the "Force using fields" option).
  6. Add the fields you want to display and select the second relationship you created for them.

At this point your block should list all events for the venue of your current event. The problem that still remains is excluding the current event from that list. Follow steps take care of that:

  1. Add two "Content: Nid" fields, set one of them to use the second relationship and exlude them from display.
  2. Set a "Global: Fields comparison" filter and set it to filter out rows when the two excluded fields from above are equal: This will take care of excluding the actual event from showing in the block.

Once you place this block inside an event node page, it should display a list of Events from the same venue excluding the current event.

Cheers and let me know how this goes.


Appendix A:


enter image description here


Appendix B:


enter image description here

11
  • Gonna add some screenshots as well. Commented Apr 26, 2016 at 18:08
  • Hi @StefanosPetrakis, and thank you. Unfortunately, although I've tied steps 1 to 6 as you've suggested (hopefully correctly) the block is displaying the no results found message "No future events at name-of-venue/name-of-performer/300416 have yet been entered". In other words it's displaying the URL (venue/performer/date), rather than details (selected fields from the Event Content Type) of the event itself. If this isn't going to work, I do have an integer field, "current-user:field-user-page-nid", that stores the NID of the venue – is there any way we could use that instead?
    – Richard
    Commented Apr 27, 2016 at 14:21
  • Could you export your view in a pastebin? I would like to have a look. And I don't really understand the "In other words it's displaying the URL "(venue/performer/date)" part. But, let me first have a look at the View export and then we can look into alternatives. This issue will be solved eventually, it's not such a rarity :-) Commented Apr 29, 2016 at 10:04
  • Hi, @StefanosPetrakis hopefully this is the link you require pastebin.com/NamE4uzj. Very many thanks.
    – Richard
    Commented Apr 29, 2016 at 14:12
  • Hi @Richard, I just tried with the view you exported and it seems to work, you can have a look at Appendix B, in my answer (edited). I had to remove the date filter and adjust the "Views Displays" (admin/structure/ds/vd/manage/establishment_events_entry-block-fields/display), but the view configuration itself worked for me as expected. The nid you see in the screenshot of Appendix B, 209, is the nid of an event. Can you have another check at your view/block without the date filter? Best regards and you are welcome! Commented Apr 30, 2016 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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