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:
<?php 
 
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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.