Knowing which plugin types exist and the use case for each is important when it comes to writing modules that extend Drupal's existing functionality. If you want to add additional functionality, you need to first know which plugin type provides that functionality.
In this tutorial, we'll list some of the more commonly-used plugin types and their use case, show where you can find a more complete list of plugin types provided by core, and provide several methods for discovering existing plugins in your Drupal codebase.
Drupal uses plugins for a lot of different scenarios. Blocks, field types, menu items, breakpoints, and migrations are all examples of plugins. There are a couple of different types of plugins. Before you can create a new plugin of any type, you'll need to figure out where the plugin implementation and its metadata should live in the code base, so that the plugin manager can find plugins, and examine what functionality instances of the plugin type are expected to provide.
In this tutorial we'll:
- Demonstrate how to figure out what type of plugin you're dealing with.
- Point to additional resources showing how to implement the specific plugin type once it has been determined.
By the end of this tutorial you should have a better understanding of how to figure out the details required to implement any given plugin type.
Plugin derivatives allow a single plugin to dynamically generate multiple plugin instances based on configuration or other data. This is useful for situations where user-entered data, or other dynamic configuration, might have an impact on available plugins. Or, put another way, any time you need to be able to dynamically generate plugin definitions.
In this tutorial we'll:
- Define what plugin derivatives are
- Understand the use case for derivatives
- Examine how core uses derivatives in order to demonstrate how you could write your own plugin deriver class
In order for a plugin manager to locate instances of individual plugins within the Drupal code base it needs to know where to look, and how to interpret the data that it finds. This process is called plugin discovery and can be accomplished in several ways.
In this tutorial, we'll look at what plugin discovery is doing at a high level, and then talk about the plugin discovery methods you can choose from when defining a new plugin type.
Learn how the Plugin API takes a given plugin ID and uses it to instantiate and return a fully configured plugin object. In this tutorial we'll look at:
- What factories are, and the role they serve in the Plugin API
- The factories available in core
- Using mappers to dynamically load a plugin when you don't know the ID of the specific plugin you need.
A plugin manager is responsible for both the definition of a new plugin type, and for listing and instantiating instances of plugins of the defined type.
In this tutorial we'll:
- Define what a plugin manager is.
- Create a list of all plugins of a specific type.
- Load and instantiate specific plugin instances, so we can use them in our code.
The term plugin type is used as a way to provide a generic name for all plugins managed by the same plugin manager. Example plugin types include block, field widget, and image effect. A plugin type doesn't consist of any code that provides specific functionality. Instead, it provides a way to refer to the system and it describes the central purpose of all plugins of that type.
In this tutorial, we'll cover what the term plugin type means and how it is used when talking about Drupal's plugin system. By the end of this tutorial, you'll understand what a plugin type is and be ready to learn how to define a plugin type in a module.
What Are Plugins?
FreeThe Drupal plugin system allows a particular module or subsystem to provide functionality in an extensible, object-oriented way. The controlling module defines the basic framework (interface) for the functionality, and other modules can create plugins (implementing the interface) with particular behaviors. Plugins are grouped into plugin types. Each plugin type is managed by a plugin manager service, which uses a plugin discovery method to discover provided plugins of that type and instantiate them using a plugin factory.
The system aims to make it easy for developers to allow for management of these components via the user interface, giving more flexibility and control to site administrators.
In this tutorial we'll take a high-level look at the problem the Plugin API is solving and provide a starting point for diving deeper into the various components that make up the Plugin API.
Create an image file programmatically and attach a file to a node.
Check and create taxonomy terms programmatically.
Drupal 8 Is 1 Year Old
Blog postIt’s hard to believe, but it has been 1 year since Drupal 8.0 was released to the world. We’re celebrating Drupal 8’s first birthday on November 19th by giving FREE access to our full Drupal 8 Migration Guide over the celebration weekend! This Saturday, November 19th through Monday, November 21st you can learn how to use the new core migration system to upgrade your Drupal site or import content from external sources. It’s time to get using Drupal 8!
When we were considering switching to the Pantheon hosting platform, one of the features that made us confident in our decision is what they call Multidev.
At its core, Multidev is just a method of spinning up complete environments for code that hasn't yet been merged into the main development branch. The main benefit to this is that it makes it incredibly easy to build a complete website environment that parallels your live site where any team member can functionally and visually test changes before they're fully merged.
This blog post covers the Drupalize.Me team's development workflow, and how we're using Pantheon's Multidev to be more efficient.
The New Drupal 8 Initiatives
Blog postYou may have heard of a variety of Drupal 8 initiatives during the development cycle leading up to Drupal 8.0.0 being released in 2015. These were officially recognized efforts to get a variety of big changes into Drupal 8, and included projects such as configuration management, Views in core, and multilingual improvements. A lot of work from those initiatives is now part of Drupal 8. Not everything got in though, and as time moves on some priorities for new work will always shift.
Load Testing Our Site on Pantheon
Blog postI did some load testing to try and answer the question; How did moving our site from Linode to Pantheon affect the performance–measured in response time–of our site for both members and non-members?
Annotations are specially-formatted PHP docblock comments that are used for class discovery and metadata description. While it is technically possible to use annotations for other purposes, at the moment Drupal only uses them for the plugin system.
In this tutorial we'll look at:
- What annotations are
- The use case for annotations
- How to figure out what you can put into an annotation
By the end of this tutorial you should understand how annotations are used in Drupal and how to write them in your own code.
It's best practice to access any of the services provided by Drupal via the service container to ensure the decoupled nature of these systems is respected. In order to do so, you need to know what services exists, and then, where possible, use dependency injection to use them in your code.
This tutorial walks through the process of:
- Discovering existing services and learn their machine name
- Using the machine name of service to request a copy from the service container
Catching the Spirit of Open Hardware
Blog postDrupalize.Me trainer Amber Matz attended this year's Open Hardware Summit in Portland and reports back on what she took away from the event.
Drupal Console
FreeThe Drupal Console is a suite of tools run from a command line interface (CLI) to generate boilerplate code and interact with a Drupal installation.
Note: This project is no longer actively maintained. See the Drush topic for alternative solutions.
Release Day: Object-Oriented PHP Part 4
Blog postIn part 4 of this series on object-oriented PHP from KnpUniversity, we'll explore static methods, namespaces, exceptions, and traits. Getting a handle on these concepts will not only help you with PHP app development, but will also help you understand what's going on under the hood of Drupal 8.
Another Version of Drupal 8
Blog postIt's that time again. October 5th brings the second minor version of Drupal 8 since moving to a semantic versioning release schedule. We've taken the time to dig through the change records and release notes (in order to make sure our tutorials stay up to date) and we want to share some of the new features and functionality you can look forward to when you upgrade to version 8.2.