Exercise on Menu Hook - Drupal Training Curriculum for Drupal Companies

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

Back to Drupal exercises for the in-class training

Exercise on Menu Hook

Areas covered

  • Drupal code base
  • Implementation of hooks
  • Drupal Database structure

Question 1: Build a Hook Menu in PHP

Write a php application that supports modules and the hook_menu. Any number of modules can be added to the applications modules directory. Each module can implement its own hook_menu. The menu implemented by the modules should be accessible from the index.php by giving the path as query string. Eg. index.php?q=/stock/add

For simplicity hook_menu structure should only consist of paths and function names. A menu implementation can have multiple paths and functions.

An example hook implementation:

hello.module

function hello_menu() {
$menu['hello/print'] = 'hello_print';
$menu['hello/add'] = 'hello_add';
return $menu;
}

function hello_print() {
echo "Hello! I'm from hello module";
}

function hello_add() {
echo "Hello added from hello module;
}

It should be able to execute the function hello_print in index.php

index.php?q=hello/print will display Hello! I'm from hello module

Question 2 : Build a query to fetch content from Drupal database

Create a website using drupal configuration.
Create a content type named 'gallery_item' with fields title, image, category, tags and five star rating and featured checkbox
On Gallery page, it shoukd list all images as thumbnails with title.
On clicking on thumbnail of any image, a popup colorbox should appear showing image in bigger size.
On clicking the title of an image in Gallery page, it should show the full size image in a separate page with rating, tags and category.
On gallery page, there should a block showing most rated images in smaller thumbnails.

Prepare necessary queries to list the gallery items - Title, Image, Category, Tags, Five Star rating, Featured. Write required functions to return the data in an array.