Creating a custom plugin type
The plugin system provides a means to create specialized objects in Drupal that do not require the data storage features of the entity system. As we have seen with the block and field plugins, each plugin type serves a specific purpose and allows for extensibility.
In this recipe, we will create a new plugin type called GeoLocator
, which will return the country code for a given IP address. We will create a plugin manager, a default plugin interface, a plugin annotation definition, and plugin implementations. A Content Delivery Network (CDN) commonly provides HTTP headers with the visitor’s country code. We will provide plugins for Cloudflare and AWS CloudFront.