jofitz: How to create a custom Drupal plugin

Over the recent weeks and months I have been creating custom Drupal plugins for various modules so now is the ideal time for me to write a "how to..." article on this topic.

Introduction

For a full explanation of the definition and purpose of Drupal plugins I recommend reading the Plugin API overview. For the purposes of this article I will quote the pithy sentence at the beginning of the documentation:

Plugins are small pieces of functionality that are swappable.

To create a custom plugin you will require the following five elements:

  • Plugin Manager
  • Interface
  • Plugin Base
  • Attribute
  • A Plugin

The following sections will cover each of these elements.

Interface

(optional)
As in vanilla php object oriented classes, it is optional to include a plugin interface, but is strongly recommended if there are methods and properties that the plugin must implement.

In the example below all plugins of this type must carry out some form of processing in the method process(). For simplicity I am creating this in a...

Read more
PubDate

Tags