diff --git a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php index b063627..83d3790 100644 --- a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php +++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php @@ -32,13 +32,6 @@ protected $factory; /** - * The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. - * - * @var \Drupal\Component\Plugin\Mapper\MapperInterface - */ - protected $mapper; - - /** * {@inheritdoc} */ public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { @@ -72,11 +65,4 @@ public function createInstance($plugin_id, array $configuration = array()) { } } - /** - * {@inheritdoc} - */ - public function getInstance(array $options) { - return $this->mapper->getInstance($options); - } - } diff --git a/core/lib/Drupal/Component/Plugin/PluginManagerInterface.php b/core/lib/Drupal/Component/Plugin/PluginManagerInterface.php index 803682a..8a46834 100644 --- a/core/lib/Drupal/Component/Plugin/PluginManagerInterface.php +++ b/core/lib/Drupal/Component/Plugin/PluginManagerInterface.php @@ -8,7 +8,6 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Factory\FactoryInterface; -use Drupal\Component\Plugin\Mapper\MapperInterface; /** * Interface implemented by plugin managers. @@ -29,5 +28,5 @@ * * @ingroup plugin_api */ -interface PluginManagerInterface extends DiscoveryInterface, FactoryInterface, MapperInterface { +interface PluginManagerInterface extends DiscoveryInterface, FactoryInterface { } diff --git a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php index 278e3c4..4a3d062 100644 --- a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php @@ -53,4 +53,17 @@ public function getSelectionGroups($entity_type_id); */ public function getSelectionHandler(FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL); + /** + * Returns a preconfigured selector instance. + * + * @param array $options + * Keys are: + * - target_type (required): the ID of the entity type that is referenced. + * - handler (optional): The ID of the selector to use. + * + * @return \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface|false + * If no instance can be retrieved, FALSE will be returned. + */ + public function getInstance(array $options); + } diff --git a/core/lib/Drupal/Core/Field/FormatterPluginManager.php b/core/lib/Drupal/Core/Field/FormatterPluginManager.php index e6054a9..49638c9 100644 --- a/core/lib/Drupal/Core/Field/FormatterPluginManager.php +++ b/core/lib/Drupal/Core/Field/FormatterPluginManager.php @@ -17,7 +17,7 @@ * * @ingroup field_formatter */ -class FormatterPluginManager extends DefaultPluginManager { +class FormatterPluginManager extends DefaultPluginManager implements FormatterPluginManagerInterface { /** * An array of formatter options for each field type. @@ -73,30 +73,7 @@ public function createInstance($plugin_id, array $configuration = array()) { } /** - * Overrides PluginManagerBase::getInstance(). - * - * @param array $options - * An array with the following key/value pairs: - * - field_definition: (FieldDefinitionInterface) The field definition. - * - view_mode: (string) The view mode. - * - prepare: (bool, optional) Whether default values should get merged in - * the 'configuration' array. Defaults to TRUE. - * - configuration: (array) the configuration for the formatter. The - * following key value pairs are allowed, and are all optional if - * 'prepare' is TRUE: - * - label: (string) Position of the label. The default 'field' theme - * implementation supports the values 'inline', 'above' and 'hidden'. - * Defaults to 'above'. - * - type: (string) The formatter to use. Defaults to the - * 'default_formatter' for the field type, The default formatter will - * also be used if the requested formatter is not available. - * - settings: (array) Settings specific to the formatter. Each setting - * defaults to the default value specified in the formatter definition. - * - third_party_settings: (array) Settings provided by other extensions - * through hook_field_formatter_third_party_settings_form(). - * - * @return \Drupal\Core\Field\FormatterInterface|null - * A formatter object or NULL when plugin is not found. + * {@inheritdoc} */ public function getInstance(array $options) { $configuration = $options['configuration']; @@ -119,7 +96,7 @@ public function getInstance(array $options) { // Grab the default widget for the field type. $field_type_definition = $this->fieldTypeManager->getDefinition($field_type); if (empty($field_type_definition['default_formatter'])) { - return NULL; + return FALSE; } $plugin_id = $field_type_definition['default_formatter']; } diff --git a/core/lib/Drupal/Core/Field/FormatterPluginManagerInterface.php b/core/lib/Drupal/Core/Field/FormatterPluginManagerInterface.php new file mode 100644 index 0000000..5276238 --- /dev/null +++ b/core/lib/Drupal/Core/Field/FormatterPluginManagerInterface.php @@ -0,0 +1,47 @@ + 'php_mail', - * 'user' => 'devel_mail_log', - * ); - * @endcode - * - * Finally, a different system can be specified for a specific message ID (see - * the $key param), such as one of the keys used by the contact module: - * - * @code - * array( - * 'default' => 'php_mail', - * 'user' => 'devel_mail_log', - * 'contact_page_autoreply' => 'null_mail', - * ); - * @endcode - * - * Other possible uses for system include a mail-sending plugin that actually - * sends (or duplicates) each message to SMS, Twitter, instant message, etc, - * or a plugin that queues up a large number of messages for more efficient - * bulk sending or for sending via a remote gateway so as to reduce the load - * on the local server. - * - * @param array $options - * An array with the following key/value pairs: - * - module: (string) The module name which was used by - * \Drupal\Core\Mail\MailManagerInterface->mail() to invoke hook_mail(). - * - key: (string) A key to identify the email sent. The final message ID - * is a string represented as {$module}_{$key}. - * - * @return \Drupal\Core\Mail\MailInterface - * A mail plugin instance. - * - * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + * {@inheritdoc} */ public function getInstance(array $options) { $module = $options['module']; diff --git a/core/lib/Drupal/Core/Mail/MailManagerInterface.php b/core/lib/Drupal/Core/Mail/MailManagerInterface.php index 5cb446a..9cc43ff 100644 --- a/core/lib/Drupal/Core/Mail/MailManagerInterface.php +++ b/core/lib/Drupal/Core/Mail/MailManagerInterface.php @@ -125,4 +125,60 @@ */ public function mail($module, $key, $to, $langcode, $params = array(), $reply = NULL, $send = TRUE); + /** + * Overrides PluginManagerBase::getInstance(). + * + * Returns an instance of the mail plugin to use for a given message ID. + * + * The selection of a particular implementation is controlled via the config + * 'system.mail.interface', which is a keyed array. The default + * implementation is the mail plugin whose ID is the value of 'default' key. A + * more specific match first to key and then to module will be used in + * preference to the default. To specify a different plugin for all mail sent + * by one module, set the plugin ID as the value for the key corresponding to + * the module name. To specify a plugin for a particular message sent by one + * module, set the plugin ID as the value for the array key that is the + * message ID, which is "${module}_${key}". + * + * For example to debug all mail sent by the user module by logging it to a + * file, you might set the variable as something like: + * + * @code + * array( + * 'default' => 'php_mail', + * 'user' => 'devel_mail_log', + * ); + * @endcode + * + * Finally, a different system can be specified for a specific message ID (see + * the $key param), such as one of the keys used by the contact module: + * + * @code + * array( + * 'default' => 'php_mail', + * 'user' => 'devel_mail_log', + * 'contact_page_autoreply' => 'null_mail', + * ); + * @endcode + * + * Other possible uses for system include a mail-sending plugin that actually + * sends (or duplicates) each message to SMS, Twitter, instant message, etc, + * or a plugin that queues up a large number of messages for more efficient + * bulk sending or for sending via a remote gateway so as to reduce the load + * on the local server. + * + * @param array $options + * An array with the following key/value pairs: + * - module: (string) The module name which was used by + * \Drupal\Core\Mail\MailManagerInterface->mail() to invoke hook_mail(). + * - key: (string) A key to identify the email sent. The final message ID + * is a string represented as {$module}_{$key}. + * + * @return \Drupal\Core\Mail\MailInterface + * A mail plugin instance. + * + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + */ + public function getInstance(array $options); + } diff --git a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php index 97594c4..ecdca8d 100644 --- a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php @@ -19,7 +19,7 @@ * @see \Drupal\rest\Plugin\ResourceInterface * @see plugin_api */ -class ResourcePluginManager extends DefaultPluginManager { +class ResourcePluginManager extends DefaultPluginManager implements ResourcePluginManagerInterface { /** * Constructs a new \Drupal\rest\Plugin\Type\ResourcePluginManager object. @@ -39,12 +39,4 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $this->alterInfo('rest_resource'); } - /** - * Overrides Drupal\Component\Plugin\PluginManagerBase::getInstance(). - */ - public function getInstance(array $options){ - if (isset($options['id'])) { - return $this->createInstance($options['id']); - } - } } diff --git a/core/modules/rest/src/Plugin/Type/ResourcePluginManagerInterface.php b/core/modules/rest/src/Plugin/Type/ResourcePluginManagerInterface.php new file mode 100644 index 0000000..e90e9d6 --- /dev/null +++ b/core/modules/rest/src/Plugin/Type/ResourcePluginManagerInterface.php @@ -0,0 +1,21 @@ +container ->get('plugin.manager.rest') - ->getInstance(array('id' => $plugin)); + ->createInstance($plugin); // Deserialize incoming data if available. $serializer = $this->container->get('serializer'); diff --git a/core/modules/rest/src/RestPermissions.php b/core/modules/rest/src/RestPermissions.php index 652ae1d..daba66c 100644 --- a/core/modules/rest/src/RestPermissions.php +++ b/core/modules/rest/src/RestPermissions.php @@ -9,7 +9,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\rest\Plugin\Type\ResourcePluginManager; +use Drupal\rest\Plugin\Type\ResourcePluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -20,7 +20,7 @@ class RestPermissions implements ContainerInjectionInterface { /** * The rest resource plugin manager. * - * @var \Drupal\rest\Plugin\Type\ResourcePluginManager + * @var \Drupal\rest\Plugin\Type\ResourcePluginManagerInterface */ protected $restPluginManager; @@ -34,12 +34,12 @@ class RestPermissions implements ContainerInjectionInterface { /** * Constructs a new RestPermissions instance. * - * @param \Drupal\rest\Plugin\Type\ResourcePluginManager $rest_plugin_manager + * @param \Drupal\rest\Plugin\Type\ResourcePluginManagerInterface $rest_plugin_manager * The rest resource plugin manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. */ - public function __construct(ResourcePluginManager $rest_plugin_manager, ConfigFactoryInterface $config_factory) { + public function __construct(ResourcePluginManagerInterface $rest_plugin_manager, ConfigFactoryInterface $config_factory) { $this->restPluginManager = $rest_plugin_manager; $this->configFactory = $config_factory; } @@ -61,7 +61,7 @@ public function permissions() { $resources = $this->configFactory->get('rest.settings')->get('resources'); if ($resources && $enabled = array_intersect_key($this->restPluginManager->getDefinitions(), $resources)) { foreach ($enabled as $key => $resource) { - $plugin = $this->restPluginManager->getInstance(['id' => $key]); + $plugin = $this->restPluginManager->createInstance($key); $permissions = array_merge($permissions, $plugin->permissions()); } } diff --git a/core/modules/rest/src/Routing/ResourceRoutes.php b/core/modules/rest/src/Routing/ResourceRoutes.php index db439dc..8175365 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -10,7 +10,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Routing\RouteSubscriberBase; -use Drupal\rest\Plugin\Type\ResourcePluginManager; +use Drupal\rest\Plugin\Type\ResourcePluginManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -24,7 +24,7 @@ class ResourceRoutes extends RouteSubscriberBase{ /** * The plugin manager for REST plugins. * - * @var \Drupal\rest\Plugin\Type\ResourcePluginManager + * @var \Drupal\rest\Plugin\Type\ResourcePluginManagerInterface */ protected $manager; @@ -45,14 +45,14 @@ class ResourceRoutes extends RouteSubscriberBase{ /** * Constructs a RouteSubscriber object. * - * @param \Drupal\rest\Plugin\Type\ResourcePluginManager $manager + * @param \Drupal\rest\Plugin\Type\ResourcePluginManagerInterface $manager * The resource plugin manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config * The configuration factory holding resource settings. * @param \Psr\Log\LoggerInterface $logger * A logger instance. */ - public function __construct(ResourcePluginManager $manager, ConfigFactoryInterface $config, LoggerInterface $logger) { + public function __construct(ResourcePluginManagerInterface $manager, ConfigFactoryInterface $config, LoggerInterface $logger) { $this->manager = $manager; $this->config = $config; $this->logger = $logger; @@ -71,7 +71,7 @@ protected function alterRoutes(RouteCollection $collection) { // Iterate over all enabled resource plugins. foreach ($enabled_resources as $id => $enabled_methods) { - $plugin = $this->manager->getInstance(array('id' => $id)); + $plugin = $this->manager->createInstance($id); foreach ($plugin->routes() as $name => $route) { $method = $route->getRequirement('_method');