Community Documentation

Step by step guide to create an event listing with calendar block in Drupal 7

Last updated November 20, 2011. Created by juampy on August 16, 2011.
Edited by KarenS, jmary. Log in to edit this page.

The contents of this guide should be tested along the Events calendar feature module as a working example. It is recommended to install and test this feature module first and dive into the step by step guide if needed.

Below are the list of steps to create an events listing with a calendar block which filters them.

Download and enable the required modules

  • latest development build of calendar, date, ctools and views modules
  • context and context_ui.
  • features (needed by the feature module mentioned above).

Create an Events content type

Go to Structure > content types > add new content type and create one with the following settings:

  • Name: Event
  • Fields: Add a field of type date, field name event_date and label Date(s). In the field configuration screen check the "Required field" and "Collect an end date" checkboxes.
  • Create three or four events at the "Add content".

Create a view to list events

Go to Structure > views > add new view and create a view showing nodes of type "Event". Click on "Save and edit".

Set the path of this page view to /events.

Add the following Contextual Filter (find the link at the Contextual Filters block when editing the view):

  1. In the search field type "Date: Date (node)", once found click on "Add and configure contextual filters".
  2. At the "When the filter value is NOT in the URL", select "Provide default value".
  3. At Type in the drop-down list, select Current Date.
  4. At Date field(s), select "field_event_date".
  5. At Method, select "AND".
  6. Save.

Create a calendar block for events

  1. Clone the view "Calendar" into "Events calendar".
  2. Select the Block display and add a filter by content type so it only lists content of type "Event".
  3. Edit the Contextual Filter so it looks exactly the same as the one we configured at the Events view
  4. Save.

Add the calendar block to the events view

  1. Using context module, create a context so if the condition is the Events view, display the "Events Calendar" block in the sidebar
  2. Save the context
  3. Verify that opening /events lists the created events with a calendar block at the sidebar.

Link the calendar block links with the events view

Add the following code to your default theme. Remember to change "yourtheme" by the name of the default theme. This code shoud reside at sites/all/themes/yourtheme/template.php

/**
* Alters link url in calendar events block in order to filter events at /events
*
* @see template_preprocess_calendar_datebox()
*/
function yourtheme_preprocess_calendar_datebox(&$vars) {
  $date = $vars['date'];
  $view = $vars['view'];
  $day_path = calendar_granularity_path($view, 'day');
  $vars['url'] = 'events/' . $date;
  $vars['link'] = !empty($day_path) ? l($vars['day'], $vars['url']) : $vars['day'];
}

Comments

Calendar problems

Hello,

I can see that there are technical reviews needed, but I tried out this step by step :
My problem is : when clicking on an date with event in the calendar (i.e. 20 oct), i get :
1) a second calendar below the first one with a totally other date with event (i.e. 30 oct)
2) This message : Debug :
'calendar_plugin_style: Missing calendar row plugin'
dans calendar_plugin_style->render() (ligne 205 dans ...\sites\all\modules\calendar\includes\calendar_plugin_style.inc).

Can you give me a hint how to get this thing working ?

Requirements

Does your test meet the requirements for the required modules? (See "Download and enable the required modules" at the top of the page).

Issue with future events by day in events view

I have a strange issue. I cannot acces future events via the link in the calendar.

Lets say I have an event on 2011-12-24

events/2011-12-24 <- shows nothing
events/2011-12 <- shows all events in 2011-12, including -24
events/2011 <- shows correctly too

All events in the past work fine. The upcoming events block also works correctly.

Any ideas?

Number links going to page not found

I have tried to get this going but have ran into a little roadblock. I have 2 post types with events in both types created. When I go to the monthly calendar (www.mydrupalinstall.com/calendar/month) I am shown all the events for those two post types and the event titles work just fine, but when I click the numbers I get sent to a page not found (www.mydrupalinstall.com/events/2012-01-11). This also happens when I use the block calendar and click on a number.

When I disable the module the numbers take me to the day view of the calendar and show that days events.

I have tested (www.mydrupalinstall.com/events/) and get page not found. Am I missing something? Why are the numbers pointing to "/events/2012-01-11" and not the event? Am I supposed to create a new view that lists all events for a certain day?

I am still a bit green when it comes to Drupal so please be gentle.

same issue

i have a similar issue basically my view sum up the amount of events I have for the day and displays the follow message on my calendar (click to see all xxx events). Here is the problem the URL doesn't show up like the example my-drupal-install.com/calander/month/2012-05-01 instead it shows up like this my-drupal-install.com//2012-05-01.

I tried both ways but none shows the list of my events.

Future-proof?

I wonder if the same can be achieved using the new create-from-template process of making calendars?

Page status

Needs technical review

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Developers and coders, Site administrators

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.