Friendly URL for Views Contextual Filter on a Boolean Field

I have a story content type that has a corresponding Views listing page. The stories can be flagged as Featured through a checkbox/boolean field ( field_story_featured ). The stories also have a Story Type value ( field_story_type ). The views listing page needs to have the following links at the top:

Screenshot_2017-02-08_15-05-57

The URL structure for the Views page makes the most sense as follows (purple = story type contextual filter, orange = featured contextual filter):

  • All => /stories or /stories/all
  • Featured => /stories/all/featured
  • Students => /stories/students
  • Alumni => /stories/alumni
  • Faculty => /stories/faculty

Notice that I want to use the word “featured” in the URL. Unfortunately this doesn’t work out of the box in Drupal. The value for field_story_featured  is actually either a or a 1. It doesn’t look very nice to have a url like /stories/all/1  but we can remedy that with a little PHP in the field’s contextual filter:

Screenshot_2017-02-08_15-22-05

Screenshot_2017-02-08_15-21-12

PHP validate code:

 

Tagged with: , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*