Problem/Motivation
The ViewExecutable class still has a lot of public properties, let's remove some of them, which aren't actually needed:
/**
* The current page. If the view uses pagination.
*
* @var int
*/
public $current_page = NULL;
/**
* The number of items per page.
*
* @var int
*/
public $items_per_page = NULL;
/**
* The pager offset.
*
* @var int
*/
public $offset = NULL;
public function setCurrentPage($page) {}
public function getCurrentPage($page) {}
public function getItemsPerPage($page) {}
public function setItemsPerPage($page) {}
public function getOffset($page) {}
public function setOffset($page) {}
Proposed resolution
Replace public with protected and search for all usages of those and replace it with the appropriate method call.
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | interdiff.txt | 1.76 KB | dawehner |
| #10 | 2359703-10.patch | 3.96 KB | dawehner |
| #4 | 2359703-4.patch | 2.42 KB | michaellenahan |
Comments
Comment #1
michaellenahan commentedComment #2
michaellenahan commentedI'm confused!
Should $current_page not properly be *private* scope?
It is not used anywhere else except in the ViewExecutable class, and it is wrapped by getter and setter functions.
Both of these are referenced by Test classes, so should they not remain as public scope?
Comment #3
dawehnerWell, we don't use protected in Drupal, because subclasses can't really access it. You never know, maybe someone comes up with a subclass of ViewExecutable and then you are kinda fucked when stuff is private instead of just protected.
Comment #4
michaellenahan commentedOK. So it's just the *properties* that get set to protected. I have to learn to read better. :)
I see now that it's the getter/setter methods which allow us to set the property to protected.
Here's the patch.
As a follow-up, do the following properties need getter/setter methods, so that they can be set to protected?
- $total_rows
- $attachment_before
- $attachment_after
- $exposed_data
- $exposed_raw_input
... or is it overkill.
Comment #5
dawehnerThank you for the work! Let's set the issue to needs review in order to figure out what the testbot thinks about it ...
We can work on so many things, do you want to create an additional issue for that?
Comment #9
michaellenahan commentedNot sure what is going on here.
Test fails because ViewExecutable::setDisplay() is called without an argument.
The patch makes no change to SetDisplay() though.
Comment #10
dawehner@michaellenahan
Well, the problem is not the debug message (that one is actually intended)
but the problem is that the property is not accessible anymore (as you marked it as protected).
Instead we should check for the default value of the method result. Sadly this opens up another bug, as the display handlers might not be defined
at some point in time.
Here is an interdiff which fixes the problem.
Do you want another issue?
Comment #11
michaellenahan commentedYes please :)
Comment #12
michaellenahan commentedComment #13
dawehnerWell, the actual work was done without my work already.
Comment #14
alexpottThis issue is a prioritized change as it reduces fragility by removing public access to properties that should not be and so is allowed as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed 08bf45f and pushed to 8.0.x. Thanks!
Unused use added.