-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Promote use of addViewClasses() instead of overriding viewClasses() #7747
Conversation
I'd say both are valid options but I don't know which one we should recommend as a default |
Method overriding as a default doesn't make sense when we already have the API to achieve the same result with a method call. |
By this logic we shouldn't overwrite/extend the Besides, your docs are missing a If we go this way then (imho) we should remove the |
That's an apples to oranges comparison since initialize() isn't for one specialized task and there's no other alternative to overriding it.
I can idiot proof the examples.
There's no need to remove it, just not documenting overriding it is enough. You can't prevent users from overriding any other controller method anyway. |
Technically one could overwrite the constructor of the controller to add "initialize" logic to it but having a simpler In the end I am fine with either approaches, I just prefer the current way of using |
The problem with viewClasses() overriding was that one couldn't change the classes from outside the controller, for e.g. a component or custom implementation like action classes of the Crud plugin, which was possible with RequestHandler. That's why addViewClasses() was added later and it's the better API. |
And similarly using addViewClasses() is a lot more convenient than method overriding and it also mitigates the problem I stated above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good once the calls to parent::initialize()
are added.
No description provided.