Mapping With Drupal - Alan Palazzolo [32]
For the “View name,” enter Upcoming events.
Enter a description of A table of upcoming events.
In the “Show” section, leave “Content” selected from the first drop-down. Change the “type” drop-down to “Event.” Change the “sorted by” drop-down to “Unsorted.”
Leave “Create a page” checked. This is the page that will contain the table of events. In the “Display format” section, change the first drop-down to “Table.” Change “Items to display” to 100.
Click the “Continue & edit” button.
In the “Fields” section, click the “add” button. From the list of available fields, select “Content: Event date” and click “Add and configure fields.” In the “Choose how users view dates and times” field, select the “Medium” format. You could create custom date formats using the link below that field, but this is not necessary. Click the “Apply (all displays)” button.
In the “Fields” section, click the “add” button. Select “Content: Event location” from the list of available fields and click “Add and configure fields.” Click the “Apply (all displays)” button.
In the “Fields” section, click the “add” button. Select “Content: Body” from the list of available fields and click “Add and configure fields.” Change the “Label” field to Description. Expand the “Rewrite Results” section. Tick the “Trim this field to a maximum length” checkbox. Enter 100 as the maximum length. Leave the “Trim only on a word boundary” and “Add an ellipsis” checkboxes ticked. Again, click the “Apply (all displays)” button.
Below the view configuration form is a preview of the table that you are creating. The header of the table displays the field labels, but the header for the event name is missing. To fix this, click on the “Content: Title” link in the “Fields” section. Tick the “Create a label” checkbox. Enter Event in the “Label” field. Click the “Apply (all displays)” button.
To make a more useful interface, we can take advantage of some of the geographic information that is associated with these events. A list of countries will be added to the page, which people can use to find events just in a particular country. From the “Filter criteria” section click the “add” button. From the list of available filters select “Content: Event location (field_event_location:country)” and click the “Add and configure filter criteria” button. Tick the “Expose this filter to visitors, to allow them to change it” checkbox. Change the “Label” field to Event country. Leave the “Operator” settings with the default values. Click the “Apply (all displays)” button.
The events now need to be sorted by their date. From the “Sort criteria” section click the “add” button. Select “Content: Event date (field_event_date)” from the list of available sort criteria and click the “Add and configure sort criteria” button. Leave “Sort ascending” selected. Click the “Apply (all displays)” button.
The user might select a country such as Antarctica that has no events, so we could provide some text for when this happens. The “Advanced” section of the view configuration form has a “No results behavior” section. Here, click the “add” button. Select “Global: Text area” from the available behaviors. Click the “Add and configure” button. In the main text field, enter some text like There are no events listed in that country. Click the “Apply (all displays)” button.
Click the “Save” button on the top right to create the view. It should look something like Figure 4-14.
Figure 4-14. Table view of geographic data
The example above is a fairly simple one, and there are many other things that can be done with Views. A list or table view can be attached to a map view using a Views attachment, so that users can see a list of locations below the map.
Proximity is a useful piece of data to have. If you are using the Location module, its Views integration includes a proximity field (how close is this place to another place), a proximity filter (show me only things that are within 10 miles of this place), a proximity argument (like a proximity filter that