-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BDE 4.x: move all code in RawDrupalContext to services #316
Comments
Absolutely! This is the kind of cleanup and refactoring I'd love to see for the next major release! |
I have a real use case for this now: I'm using the Email Registration module in a project which alters the standard login form to allow to log in users with their e-mail address rather than their user name. The username field is replaced with an email field. This causes the current implementation to fail, since We can solve this by extending It is not possible to do this in a subcontext, this is too late, the services have all been instantiated already at that point. |
Had a look, |
I'm using Email Registration in D8, and get Behat working by using in behat.yml
But probably you know that and have more complex needs. |
Well that only works if you have the option "Also allow to log in using the username" enabled, not in the default configuration where logging in with the username throws an error. But I don't want to solve this for the sake of Email Registration, but for anyone who doesn't use the standard login form from Drupal core for authenticating. I just think that Email Registration is a nice and simple use case for this issue, it's a lot easier to set up than things like OAuth or single sign on. As an added bonus, I'm actually using Email Registration in a project which is a good motivation for actually getting this done :) |
Hello there ! I'm actually having the same issue kinda, we use SSO (shibboleth) and need to do exactly what @pfrenssen is suggesting. I'm still discovering behat but tell me if I can help ! |
I'm going to start working on the user authentication service. |
Now that user manager and authentication manager are done, what's left to do here? The entity field parser looks like a good candidate, are there others? |
One area that occurs to me offhand has to do with post-scenario cleanup. We actually use a custom module that calls back to our testing code whenever a new entity is created; this is in response to supplementary nodes that are created in response to the creation of certain node types in our system. The addition of type A automatically creates type B sort of thing. It would be nice to be able to add our own generated content manager that would provide an api for cleanup that the core system would leverage? |
I think that's best handled in the bigger context of #337. My idea is use D8's core-plugins component as a composer dependency and build Field and Entity plugin systems using that. Invoking the plugins would be the job of plugin manager field and entity services. I'm keen to work on it but unsure when I'll be able to. I think this would help with the cleanup @aronbeal asks for, as entity plugins could have a postDelete method that cleaned up any of their autocreated offspring. |
@pfrenssen @jhedstrom Apologies for the late request for handholding. I promise to document thoroughly... but what is the recommended way to override a service like the AuthenticationManager one introduced in #425 ? Is it still basically the same approach used in https://www.drupal.org/project/email_registration/issues/2843505 (which code dates from before the above code was merged), using https://github.com/FriendsOfBehat/ServiceContainerExtension ? Or do these improvements make that unnecessary? In short: Where should a project place a service such as an AuthenticationManagerInterface implementation, and where/how (in behat.yml?) should we instruct that our custom implementation be used? (Using DrupalExtension 4.x of course.) |
This is based on my comment #267 (comment)
Currently we are having a whole bunch of commonly used functionality in
RawDrupalContext
, and this is extended by all the context classes that BDE provides.This is problematic, it is practically impossible to modify the behaviour of these methods. The only way a method can be overridden is by extending
RawDrupalContext
with a custom class likeMyCustomContext
, but then the modified version is only available toMyCustomContext
, all other classes likeDrupalContext
andFeatureContext
will still extend the originalRawDrupalContext
and are not using the customized behaviour. They are effectively hardcoded to a single implementation that cannot be modified.For example, imagine you are working on a project that uses single sign-on instead of the standard Drupal login form. You implement your own
MyCustomContext
class that overridesRawDrupalContext::loggedIn()
with your custom logic that checks access with the 3rd party authentication provider.Using the inheritance based approach this now completely falls apart, since there are a bunch of other classes (like
DrupalContext
,DrushContext
,FeatureContext
etc) that are still hardcoded to extend the originalRawDrupalContext
, and are using the original behaviour instead of your custom behaviour. This causes some step definitions to use the original Drupal login form, while others use the SSO provider, chaos!Using inheritance is the wrong solution for sharing code between classes. Inheritance should be used only to provide different implementations of code that adheres to a specific interface. For solving this problem we should use composition instead. Currently this is usually solved using services and dependency injection.
So a proper solution would be to encapsulate all user authentication related code in a
UserManager
service that adheres to aUserManagerInterface
and call this instead. This means we can then swap out any implementation with a custom one at runtime.Here's an example from
DrupalContext
, this is the current (bad) implementation:The solution would be to inject the
UserManager
service, so that this can be swapped out with custom functionality if needed:Is this something we can aim for for the 4.x branch?
The text was updated successfully, but these errors were encountered: