How to do it...

  1. All plugins need to have a service that acts as a plugin manager. Create a new file in your module's src directory called GeoLocatorManager.php. This will hold the GeoLocatorManager class.
  2. Create the GeoLocatorManager class by extending the \Drupal\Core\Plugin\DefaultPluginManager class:
namespace Drupal\geoip; 
use Drupal\Core\Plugin\DefaultPluginManager; 
use Drupal\Core\Cache\CacheBackendInterface; 
use Drupal\Core\Extension\ModuleHandlerInterface; 
class GeoLocatorManager extends DefaultPluginManager { 
  1. When creating a new plugin type, it is recommended that the plugin manager provides a set of defaults for new plugins, in case an item is missing from the definition:
<?php namespace Drupal\geoip; use Drupal\Core\Plugin\DefaultPluginManager; ...

Get Drupal 8 Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.