Problem/Motivation
Class ConnectionBase uses the function create with ContainerInterface $container as first parameter, which is used to set the LoggerChannelInterface.
However, when the class does not implement ContainerFactoryPluginInterface, the plugin instance won't be created using its factory method.
The function below is what actually creates the plugin instance. Currently, the is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface') fails.
/**
* Plugin factory which passes a container to a create method.
*/
class ContainerFactory extends DefaultFactory {
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = []) {
$plugin_definition = $this->discovery->getDefinition($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $plugin_definition, $this->interface);
// If the plugin provides a factory method, pass the container to it.
if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
}
// Otherwise, create the plugin directly.
return new $plugin_class($configuration, $plugin_id, $plugin_definition);
}
}
This causes the LoggerChannelInterface to be missing in the Connection plugin(s).
Steps to reproduce
- I couldn't find any code actually triggering the \Drupal\mailgroup\ConnectionInterface::testConnection function, so I added
$group->testConnection();to\Drupal\mailgroup\Entity\Form\MailGroupForm::save. - Choose IMAP or POP3 Connection plugin, leave the plugin input fields blank and save the form. Now you should see the error below.
The website encountered an unexpected error. Please try again later.
Error: Call to a member function error() on null in Drupal\mailgroup\Plugin\Mailgroup\Connection\Basic->testConnection() (line 79 of modules/contrib/mailgroup/src/Plugin/Mailgroup/Connection/Basic.php). Proposed resolution
Change the classs to implement ContainerFactoryPluginInterface.
Issue fork mailgroup-3275659
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
andreasderijckeMerge request created.
Comment #6
davisbenThis has been merged.