Check your version
This tutorial covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.
Create a custom module and alter the content on a node page using a hook and existing theme functions.
Goal
Add custom links to the Movie Review page using hook_node_view()
.
Prerequisites
You will need the following knowledge and skills. If you need a review, check out the Additional resources section at the bottom of this page.
- How to create a custom module.
- Understand how to add custom content to the "Movie Review" page.
- How to use existing theme functions to create markup.
Tasks
Create a custom module with info and module files.
Use
hook_node_view
to replace the default Genre taxonomy links with custom links on the Movie Review page. The URL format of the new links should be as follows: <a href="https://drupalize.me/reviews/%7Bgenre%7D%E2%80%9D%3E%7Bgenre%7D%3C/a%3E%3C/code%3E.%3C/p%3E_%3Cp%3E%3C/div%3E_%3Cdiv%20class%3D"tutorial--steps-step">
The links should be in an unordered list.
Both the links and list should be themed using existing Drupal functions.
Recap
- We can alter markup within a node page by using the
node_view
hook. - Markup should be generated only by existing theme functions where possible.
Further your understanding
- Continue to the next lesson: Movie Project: Change a Page Programmatically.
Additional resources
- Video: Anatomy of a Drupal Module (Drupalize.Me)
- Understanding the hook system for Drupal modules (Drupal.org)
- Video: The Event-Driven Hook System (Drupalize.Me)
- API Documentation: hook_node_view (api.drupal.org)
- Video: Integrating with the Theme System (Drupalize.Me)
- API Documentation: Taxonomy functions (api.drupal.org)
- API Documentation: Theme functions (api.drupal.org)