Problem/Motivation
@alexpott mentioned we should not have a setId() in core/lib/Drupal/Core/Language/LanguageInterface.php
and just set it in the constructor (and the id should not change after it is created).
Proposed resolution
Remove setId() from core/lib/Drupal/Core/Language/LanguageInterface.php
, core/modules/language/src/Entity/Language.php
.
Remaining tasks
- new patch needed with reduced scope. git instructions for creating patch | Contributor task documentation for creating a patch
- Review patch to check it fixes the issue, the change is properly documented and for coding standards. Make sure patch stays within scope of just this issue. | Contributor task documentation for reviewing patch
User interface changes
No
API changes
Yes
Changes:
- remove method setId()
Comments
Comment #1
alimac CreditAttribution: alimac commentedComment #2
alimac CreditAttribution: alimac commented@alexpott pointed out that the setId() method was only used in tests (in phpStorm, right click on the method name and select Find Usages to find usages of a particular method). The value of id is set in the constructor and should not be modified afterward.
This patch removes the setId() method from
core/lib/Drupal/Core/Language/LanguageInterface.php
,core/modules/language/src/Entity/Language.php
,core/lib/Drupal/Core/Language/Language.php
and the tests.Comment #3
alimac CreditAttribution: alimac commentedAttaching patch.
Comment #5
alimac CreditAttribution: alimac commentedRerolled.
Comment #7
alimac CreditAttribution: alimac commentedRerolled, again.
Comment #8
alimac CreditAttribution: alimac commentedComment #10
alimac CreditAttribution: alimac commentedI fixed the syntax problem and @jmolivas spotted an extraneous line of code. Hopefully this one passes.
Comment #11
thehong CreditAttribution: thehong commentedI think we need add some more comment to Language.id, why there's no setter for it.
Comment #12
YesCT CreditAttribution: YesCT commented@thehong hm. Maybe, but this is a common pattern already in core. (of having an id property, a id() function (getter) and no setter).
If we wanted to add a comment explaining that id was immutable and has no setter on purpose... it would be a separate issue to find all the classes that have a protected id which does not have a setter, and add a similar comment to all of them.
Comment #13
martin107 CreditAttribution: martin107 commentedI agree with the thrust of the issue...
In terms of review....
1) The implementation makes complete sense.
2) The immutability argument in #12 follows a recognizable established pattern.
3) After a slow and steady scan of the patch - nothing is out scope or inappropriate.
So +1 from me.
Comment #14
thehong CreditAttribution: thehong commentedI think this is small issue with coding standard, should change to
array('key' => 'value')
Comment #15
thehong CreditAttribution: thehong commentedComment #16
martin107 CreditAttribution: martin107 commented@thehong forgive me but I don't understand what you are saying.
Comment #17
thehong CreditAttribution: thehong commented@martin107, the patch is just missing spaces around '=>'. Please check more at https://www.drupal.org/coding-standards#array
Comment #18
martin107 CreditAttribution: martin107 commentedAh thank you ... fixed.
Comment #19
penyaskitoMuch more sense. RTBC.
Comment #20
penyaskitoRegret.
Can we use $this->language per consistence with the other tests?
Comment #22
alexpottCommitted 4b42df3 and pushed to 8.0.x. Thanks!
@penyaskito don't think that matters - it's a test - file a followup issue if you like.