Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
A lot of code in views is using __construct instead of init() even init() is the more recommended way to add things like
an additional_field.
Comment | File | Size | Author |
---|---|---|---|
#16 | views-1789948-16.patch | 23.68 KB | dawehner |
#14 | views-1789948-14.patch | 24.28 KB | dawehner |
#11 | views-1789948-11.patch | 18.69 KB | dawehner |
#9 | views-1789948-8.patch | 18.65 KB | dawehner |
#6 | views-1789948-6.patch | 18.62 KB | dawehner |
Comments
Comment #1
dawehnerI converted all __costructs which are used to add additional fields, but there are some of them which are used for other things like formula etc.
Does anyone has an oppinion whether using __construct for them might be better?
Comment #2
aspilicious CreditAttribution: aspilicious commentedYou need to remove the "use DiscoveryInterface" in those cases
*My opinion*
Don't load unneeded code. __construct is called once for each object. If init is only called once I don't care if it lives inside the __construct or the init. If the init is (possibly) called multiple times we only should add stuff in there that needs to be rebuild/reset.
Comment #3
dawehnerThat's a good point!
No init will never be called multiple times or it would be clearly a bug.
Comment #4
tim.plunkettI believe there are cases where init() is never actually called, so moving non-essential code to init() is good.
Comment #6
dawehnerOkay tim again broke the code :)
Comment #8
tim.plunkettMany of the remaining __construct() methods look like they could be converted too, especially the filter code.
Comment #9
dawehnergrr
Comment #11
dawehnerOne handler had a use missing.
Comment #12
tim.plunkettWhat about
lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php
lib/Drupal/views/Plugin/views/argument/Formula.php
lib/Drupal/views/Plugin/views/filter/BooleanOperator.php
lib/Drupal/views/Plugin/views/filter/InOperator.php
lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
lib/Views/user/Plugin/views/filter/Current.php
?
I guess the Wizard one can wait.
Comment #13
dawehnerGood question, i just converted the ones with additional_fields but yes it could make sense to convert them as well.
Comment #14
dawehnerLet's convert them other ones as well.
Wizards aren't really views plugins, so don't introduce an init method here.
Comment #15
tim.plunkettExtra line here
Isn't this just being written over?
Extra line
Extra line here
Comment #16
dawehnerRegarding the first comment. Actually we just need the last line.
Comment #17
tim.plunkettCommitted!
http://drupalcode.org/project/views.git/commit/54ebe5a