ShortcutSet class variables should not be accessed directly. Functions should be use to access the variable. For instance use getDescription() and setDescription($description) for the protected class variable description. For a boolean variable the getter function becomes isVariableName(). In object-oriented programming this is called encapsulation.
Remaining tasks
- Update the class variables and make them protected.
- Create getters and setters for frequently used get and set functionality.
- Update drupal to use the getters and setters instead of accessing variables directly.
- There are no tests required because the added functions are only getters and setters.
For more info over what should be done see the issue summary of #2016679: Expand Entity Type interfaces to provide methods, protect the properties.
Beta phase evaluation
| Issue category | Bug because properties should not be public, API methods should not be allowed to be sidestepped. |
|---|---|
| Issue priority | Major because this meta goes across the entire system. But each child will be a normal bug. |
| Prioritized changes | Prioritized since it is a bug and it reduces fragility. |
| Disruption | Somewhat disruptive for core as well as contributed and custom modules:
|
But impact will be greater than the disruption, so it is allowed in the beta.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | drupal-2384527-22.patch | 1.1 KB | preshetin |
| #21 | drupal-protecting-2384527-21.patch | 39.48 KB | tadityar |
| #15 | drupal-protecting-2384527.patch | 1.09 KB | tadityar |
| #12 | 2384527-11.patch | 581 bytes | rpayanm |
| #4 | protect-2384527-4.patch | 581 bytes | areke |
Comments
Comment #1
daffie commentedI would like to get this fixed. So I will do a good review for posted patches.
Comment #2
daffie commentedComment #3
daffie commentedThe class variables $id and $label need to become protected.
No extra functions need to be added.
Comment #4
areke commentedA patch to protect $id and $label.
Comment #5
areke commentedComment #7
daffie commentedThe reason that your patch failed testing is that outside the NodeType class the class variables are no longer accessible. And it will result in an error. Use the methods id() and label() to fix this. If you need the set a variable use set('id', $value) or set('label', $value).
Comment #8
areke commentedComment #9
rpayanmany progress @areke?
Comment #10
areke commented@rpayanm, not yet. If you want you can take it.
Comment #11
rpayanmWorking on this!
Comment #12
rpayanmLet me see.
Comment #14
rpayanmComment #15
tadityar commentedTrying.
Comment #17
tadityar commentedComment #18
daffie commentedThe problem is that the ShortcutSetsTest.php is failing. Seen as we changed the class variables from public to protected they are no longer directly accessible outside of the class ShortcutSet. Since the failing test is part of the same module shortcut as is the class. I would start by looking for places in the module where a shortcut entity is accessing the variable $id or $label directly (->id or ->label) and not via a method (->id() or ->label()). Hope this will help.
Comment #19
tadityar commented@daffie is this correct though changing the
$default_set()->id() to $default_set('id', $value)?Thank you for your explanation, gonna try again :)
Comment #20
daffie commentedThe function shortcut_default_set() returns an instance of ShortcutSet. If you want to do something with it you must use methods. If you want to set the value of the variable $id do $default_set->set('id', your_new_id_value).
Comment #21
tadityar commentedComment #23
preshetin commentedTrying. In this patch I tried to implement #18 instructions.
Comment #24
daffie commentedAll the class variables are protected.
There are already getter functions available, so no need for new ones.
The test-server give it green.
It all looks good to me, so for me it is RTBC.
Comment #25
alexpottCommitted 6031d0b and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation for to the issue summary.
We should not be changing the file modes to 755. Fixed on commit.