Last updated April 22, 2012. Created by shakty on March 2, 2012.
Edited by csko. Log in to edit this page.

Anatomy of a pattern file

A Pattern file contains an info section, and a sequence of actions uniquely identified by their tag name. Actions are grouped in coherent sections, which can be identified by any name.

Two other optional section names are modules and include. The former explicitly defines a list of modules to enable during the execution of the pattern, while the latter loads the actions of another pattern into the current one.

Therefore, a Pattern file has the following reserved words:

  • info
  • modules
  • tag
  • create, modify, delete
  • include (not yet fully implemented!)

Let us have a look at an example of Pattern file for dealing with Taxonomy operations:

# This is a comment
# Example Pattern
info: # mandatory name
  title: New Vocabulary
  description: Adds a new vocabulary to the website
  author: QScience
  category: Examples
  version: 1.0
  core: 7.x
  author_email: i@me.org
  author_website: <a href="http://qlectives.eu">http://qlectives.eu</a>
modules:
  - taxonomy # we make sure that taxonomy is enabled
actions: # any name is good for this category
  - create:
        tag: vocabulary
        name: Another Vocabulary
        machine_name: anothervoc
        description: Another interesting vocabulary
        hierarchy: 0
  - modify:
        tag: vocabulary
        machine_name: anothervoc
        description: It was not that interesting after all
        # vid: 2
  - delete:
        tag: vocabulary
        machine_name: anothervoc
        # vid: 2

In the example file, the term tag: basically tells Patterns which component to call to perform the action.

Included within the tag the data required for the vocabulary action is supplied. In this example these are:

  • name
  • machine_name
  • description
  • hierarchy

Any number of categories, in this example just actions, can be defined (excluding the reserved words) and they are executed sequentially.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.