Plugins are loaded through the manager service, which should always be accessed through the service container. The following line of code will be used in your module's hooks or classes to access the plugin manager:
$geolocator_manager = \Drupal::service('plugin.manager.geolocator');
Plugin managers have various methods for retrieving plugin definitions, which are as follows:
- getDefinitions: This method will return an array of plugin definitions. It first makes an attempt to retrieve cached definitions, if any, and sets the cache of discovered definitions before returning them.
- getDefinition: This takes an expected plugin ID and returns its definition.
- createInstance: This takes an expected plugin ID and returns an initiated class for the plugin.
- getInstance: This takes an array that acts as a plugin definition and returns an initiated class from the definition.