Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

Project: Event Listing Site

Build a complete Drupal event site: plan the content model, fields, a Views listing with filters, a theme template, permissions, caching and deployment, with a data-model stand-in.

This project ties the chapters together. You will plan and build a small site where editors publish events and visitors browse upcoming ones, filter by category and read details. It uses a content type, fields, taxonomy, a View, a template override, roles and caching, and ends with configuration export. Drupal itself cannot run on this site, so the steps are written for your own local Drupal (DDEV, Lando or Docker) and shown read-only. The TryIt blocks are JavaScript stand-ins for the logic you will configure.

1. Plan the content model

Write the model on paper first. For each event:

  • Title (required) and Description (formatted long text).
  • Start date and time and optional End date and time (a date range field).
  • Venue (text) and City (text or taxonomy).
  • Category (taxonomy vocabulary event_category: Music, Tech, Sports, Family).
  • Poster image (image field with alt text required).
  • Registration link (link field), Capacity (integer, optional).
  • Featured (boolean) used to highlight events on the home page.

Pick names carefully: field machine names (field_start, field_category) cannot be changed later.

Node.js Stand-in: model events and list upcoming ones

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

This is exactly what the View will do: filter by published and date, sort by start, optionally filter by category.

2. Build it in the admin UI

  1. Structure > Content types > Add content type: name Event. Untick "Promoted to front page" and "Display author and date".
  2. Manage fields: add the fields above. For the date use "Date range" (daterange), widget "Date and time range". For the image set alt required, a file directory events/[date:custom:Y-m] and allowed extensions png jpg webp.
  3. Structure > Taxonomy > Add vocabulary Event category, then add terms. Use an entity reference field with the "Create referenced entities if they don't already exist" option off, so editors pick from a controlled list.
  4. Manage form display: group fields with details elements; put Featured in the sidebar.
  5. Manage display: hide labels for most fields, use the "Responsive image" formatter for the poster, a "Default" date format of l, F j, Y - g:ia.
  6. Pathauto (contributed): pattern /events/[node:title], so URLs read well.

3. Create the listing with Views

Structure > Views > Add view "Upcoming events": show Content of type Event, create a page at /events, "Unformatted list of teasers" or a table/grid, 12 items with a full pager.

  • Filter criteria: Published (= Yes), Content type (= Event), Start date >= "now" (relative now), plus an exposed filter on Category.
  • Sort: Start date ascending.
  • Contextual filter (for a "events in city" page): City, "Provide default value" none, "Display a 404 if no match".
  • No results behaviour: a friendly message with a link to the calendar.
  • Caching: "Tag based".
  • Block display: a second display "Featured events" with Featured = Yes, 3 items, placed on the home page.

Remember the access angle: Views respects node access, and the Published filter also hides drafts from anonymous users (access control).

4. Template and styling

Teaser markup comes from node--event--teaser.html.twig in your theme (suggestions):

HTML
<article{{ attributes.addClass('event-card') }}>
  {% if content.field_poster|render|trim %}
    <div class="event-card__poster">{{ content.field_poster }}</div>
  {% endif %}
  <div class="event-card__body">
    <p class="event-card__date">{{ content.field_start }}</p>
    <h3{{ title_attributes }}><a href="{{ url }}" rel="bookmark">{{ label }}</a></h3>
    {{ content|without('field_poster', 'field_start', 'links') }}
    {% if is_past %}<span class="badge">{{ 'Past event'|t }}</span>{% endif %}
  </div>
</article>

Add is_past in preprocess (preprocess functions):

PHP
function sunrise_preprocess_node__event(array &$variables): void {
  $node = $variables['node'];
  $end = $node->get('field_start')->end_value ?? $node->get('field_start')->value;
  $variables['is_past'] = $end && strtotime($end . ' UTC') < \Drupal::time()->getRequestTime();
  $variables['#cache']['max-age'] = 3600;
}

Note the max-age: whether an event is "past" changes with time, not with an entity save, so we tell Drupal to recompute hourly (caching).

Node.js Stand-in: the is_past flag with a cache lifetime

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

5. Roles and workflow

Create roles Event editor and Event publisher:

  • Editor: create event content, edit own event content, delete own event content, access content overview, view own unpublished content.
  • Publisher: also edit any event content and use editorial transition publish with Content Moderation (Draft, In review, Published). Editors can only move Draft to In review.
  • Anonymous: access content. Nothing else.

Test with drush user:create and drush user:login.

6. Performance and security checks

  • Enable Internal Page Cache, Dynamic Page Cache and aggregation (performance).
  • Use image styles and responsive images for posters; lazy load below the fold.
  • Restrict the text format for "Description" to Basic HTML (security).
  • Add CAPTCHA/honeypot if you let visitors submit events.

7. Export and deploy

Terminal
drush config:export --yes
git add config/ && git commit -m "Event content type, view, roles"
# on staging:
drush deploy

Include the vocabulary terms with the default_content module or a migration, since taxonomy terms are content, not configuration (deployment).

Extensions to try

  • A calendar display with the Calendar or FullCalendar View modules.
  • An iCal export link (Date iCal module) for each event.
  • An RSVP form using the Webform module or your own form (Form API).
  • A custom block plugin "Next event" (plugins).
  • A JSON:API endpoint (core module) for a mobile app.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use a taxonomy vocabulary for event categories?

    Terms are reusable entities, ideal for filtering and landing pages.
  2. 2. Which Views setting hides past events?

    A relative date filter compares each event's start to the current time.
  3. 3. Why set a max-age on a template whose output depends on the current time?

    Cache tags react to data changes; a time-based change needs max-age.
  4. 4. What is not carried by config export in this project?

    Terms and nodes are content; use default content or migrations for them.

Summary

  • Plan fields and names first; build the model, taxonomy and displays in the UI.
  • A View with date, published and exposed category filters is the whole listing.
  • Override templates and add small preprocess logic; declare cache max-age for time-based output.
  • Use roles and Content Moderation for editorial control.
  • Export configuration, deploy with drush deploy, and move content separately.

Next: Project: A Notes Module from Scratch