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/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php index b5f757b..4a3d062 100644 --- a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManagerInterface.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity\EntityReferenceSelection; -use Drupal\Component\Plugin\Mapper\MapperInterface; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; @@ -15,7 +14,7 @@ /** * Defines an interface for the entity reference selection plugin manager. */ -interface SelectionPluginManagerInterface extends PluginManagerInterface, MapperInterface { +interface SelectionPluginManagerInterface extends PluginManagerInterface { /** * Gets the plugin ID for a given target entity type and base plugin ID. @@ -54,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 414ac25..49638c9 100644 --- a/core/lib/Drupal/Core/Field/FormatterPluginManager.php +++ b/core/lib/Drupal/Core/Field/FormatterPluginManager.php @@ -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 index 2bef39b..5276238 100644 --- a/core/lib/Drupal/Core/Field/FormatterPluginManagerInterface.php +++ b/core/lib/Drupal/Core/Field/FormatterPluginManagerInterface.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Field; -use Drupal\Component\Plugin\Mapper\MapperInterface; use Drupal\Component\Plugin\PluginManagerInterface; /** @@ -15,5 +14,34 @@ * * @ingroup field_formatter */ -interface FormatterPluginManagerInterface extends PluginManagerInterface, MapperInterface { +interface FormatterPluginManagerInterface extends PluginManagerInterface { + + /** + * Returns a preconfigured formatter. + * + * @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. + */ + public function getInstance(array $options); + } diff --git a/core/lib/Drupal/Core/Field/WidgetPluginManager.php b/core/lib/Drupal/Core/Field/WidgetPluginManager.php index 3779d0b..12b5c08 100644 --- a/core/lib/Drupal/Core/Field/WidgetPluginManager.php +++ b/core/lib/Drupal/Core/Field/WidgetPluginManager.php @@ -55,27 +55,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac } /** - * Overrides PluginManagerBase::getInstance(). - * - * @param array $options - * An array with the following key/value pairs: - * - field_definition: (FieldDefinitionInterface) The field definition. - * - form_mode: (string) The form mode. - * - prepare: (bool, optional) Whether default values should get merged in - * the 'configuration' array. Defaults to TRUE. - * - configuration: (array) the configuration for the widget. The - * following key value pairs are allowed, and are all optional if - * 'prepare' is TRUE: - * - type: (string) The widget to use. Defaults to the - * 'default_widget' for the field type. The default widget will also be - * used if the requested widget is not available. - * - settings: (array) Settings specific to the widget. Each setting - * defaults to the default value specified in the widget definition. - * - third_party_settings: (array) Settings provided by other extensions - * through hook_field_formatter_third_party_settings_form(). - * - * @return \Drupal\Core\Field\WidgetInterface|null - * A Widget object or NULL when plugin is not found. + * {@inheritdoc} */ public function getInstance(array $options) { // Fill in defaults for missing properties. diff --git a/core/lib/Drupal/Core/Field/WidgetPluginManagerInterface.php b/core/lib/Drupal/Core/Field/WidgetPluginManagerInterface.php index 4d019d3..2fb92f2 100644 --- a/core/lib/Drupal/Core/Field/WidgetPluginManagerInterface.php +++ b/core/lib/Drupal/Core/Field/WidgetPluginManagerInterface.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Field; -use Drupal\Component\Plugin\Mapper\MapperInterface; use Drupal\Component\Plugin\PluginManagerInterface; /** @@ -15,5 +14,30 @@ * * @ingroup field_widget */ -interface WidgetPluginManagerInterface extends PluginManagerInterface, MapperInterface { +interface WidgetPluginManagerInterface extends PluginManagerInterface { + + /** + * Returns a preconfigured widget. + * + * @param array $options + * An array with the following key/value pairs: + * - field_definition: (FieldDefinitionInterface) The field definition. + * - form_mode: (string) The form mode. + * - prepare: (bool, optional) Whether default values should get merged in + * the 'configuration' array. Defaults to TRUE. + * - configuration: (array) the configuration for the widget. The + * following key value pairs are allowed, and are all optional if + * 'prepare' is TRUE: + * - type: (string) The widget to use. Defaults to the + * 'default_widget' for the field type. The default widget will also be + * used if the requested widget is not available. + * - settings: (array) Settings specific to the widget. Each setting + * defaults to the default value specified in the widget definition. + * - third_party_settings: (array) Settings provided by other extensions + * through hook_field_formatter_third_party_settings_form(). + * + * @return \Drupal\Core\Field\WidgetInterface|null + * A Widget object or NULL when plugin is not found. + */ + public function getInstance(array $options); } diff --git a/core/lib/Drupal/Core/Mail/MailManager.php b/core/lib/Drupal/Core/Mail/MailManager.php index 1e7bdc6..c2a6197 100644 --- a/core/lib/Drupal/Core/Mail/MailManager.php +++ b/core/lib/Drupal/Core/Mail/MailManager.php @@ -74,58 +74,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac } /** - * 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 + * {@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 1e2f629..9cc43ff 100644 --- a/core/lib/Drupal/Core/Mail/MailManagerInterface.php +++ b/core/lib/Drupal/Core/Mail/MailManagerInterface.php @@ -7,13 +7,12 @@ namespace Drupal\Core\Mail; -use Drupal\Component\Plugin\Mapper\MapperInterface; use Drupal\Component\Plugin\PluginManagerInterface; /** * Provides an interface for sending mail. */ -interface MailManagerInterface extends PluginManagerInterface, MapperInterface { +interface MailManagerInterface extends PluginManagerInterface { /** * Composes and optionally sends an email message. @@ -126,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 483987e..ecdca8d 100644 --- a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php @@ -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 index 39de46f..e90e9d6 100644 --- a/core/modules/rest/src/Plugin/Type/ResourcePluginManagerInterface.php +++ b/core/modules/rest/src/Plugin/Type/ResourcePluginManagerInterface.php @@ -7,7 +7,6 @@ namespace Drupal\rest\Plugin\Type; -use Drupal\Component\Plugin\Mapper\MapperInterface; use Drupal\Component\Plugin\PluginManagerInterface; /** @@ -18,5 +17,5 @@ * @see \Drupal\rest\Plugin\ResourceInterface * @see plugin_api */ -interface ResourcePluginManagerInterface extends PluginManagerInterface, MapperInterface { +interface ResourcePluginManagerInterface extends PluginManagerInterface { } diff --git a/core/modules/rest/src/RestPermissions.php b/core/modules/rest/src/RestPermissions.php index 6528e1c..daba66c 100644 --- a/core/modules/rest/src/RestPermissions.php +++ b/core/modules/rest/src/RestPermissions.php @@ -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 594c865..8175365 100644 --- a/core/modules/rest/src/Routing/ResourceRoutes.php +++ b/core/modules/rest/src/Routing/ResourceRoutes.php @@ -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');