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.
Problem/Motivation
Reading classnames is hard when they are overgeneric. One classical example is Field
, which "obviously" is about entity fields.
This is a normal issue as this class is used quite often.
Proposed resolution
- Rename the class from
Field
toEntityField
- Provide a BC layer
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#75 | interdiff-70-75.txt | 1.53 KB | mpdonadio |
#75 | 2408667-75.patch | 59.03 KB | mpdonadio |
#74 | rename.png | 95.27 KB | lomasr |
#71 | rename_field_php_to-2408667-70.patch | 59.58 KB | marvin_B8 |
#51 | interdiff-2408667-46-51.txt | 578 bytes | marvin_B8 |
Comments
Comment #1
yched CreditAttribution: yched commented+ a ton for dropping Field as a name for that class.
For people looking into Field API classes, it's way confusing to have that class pop up in PhpSorm's "Navigate to class" / "Navigate to file" and be the most obvious contender.
EntityField is not much better, though :-/
It does clarify things internally for views (views's "fields" enclose more than entity fields, and this class here is about fields from the entity system)
Would EntityFieldHandler be acceptable ? Seeing Handler clearly points that its about integrating with some system - which system system exactly (Views) is carried by the namespace, which is perfectly fine IMO.
It's also more compliant to our coding standards: "Classes and interfaces should have names that stand alone to tell what they do without having to refer to the namespace". This is not a "field", this is a "field handler". Again, which "kind of handler ?" is carried by the namespace, fine.
Comment #2
dawehnerI'd hate that completely, it would just get rid of namespaces, which is pointless. This is encoded in the namespace, and let's be honest 95% of core also needs that,
our coding standard is just bullshit, many people disagreed with it in a long long time.
Comment #3
yched CreditAttribution: yched commentedAw. Well count me with those for which it makes a ton of sense, and would fight hard for keeping it ;-)
- If you rename NumberFormatter to Date, the class name is just a plain lie. An object that formats a Number is not a Number.
Namespaces carry domain/ownership, they should not carry role/identity.
- Then you have deeply confusing code, since once you've "use"d the fully qualified class at the top of the file, your code only works with the unqualified class name, which calls an apple an orange.
- Also very painful in IDE tabs that only show a file name (or PhpStorm CTRL-E which lists recent files)
Taking from a couple core plugin types :
All field widget classes have "Widget" in them
All field formatter classes have "Formatter"
All field item classes have "Item"
All (well, most non-test) block classes have "Block"
All filter classes have "Filter"
All image effect classes have "Effect"
All rest resource classes have "Resource"
...
But well - the fact that Views plugins (with a few other ones like Constraint, Condition, probably some others) chose not to comply is outside the scope of this rename here...
So, EntityField.php, then :-)
Comment #4
jibranComment #5
geertvd CreditAttribution: geertvd commentedComment #6
geertvd CreditAttribution: geertvd commentedComment #7
XanoCould you please roll another patch using
git diff -M
, so the rename is marked as a change, rather than a deletion+new file?Comment #8
pguillard CreditAttribution: pguillard commentedComment #9
pguillard CreditAttribution: pguillard commentedI had to reroll it manually cause the code have changed a lot since the last patch.
Here is what I get.
(I can't install Drupal anymore with the master today, so I can't launch tests, lets see what the testbot says)
Comment #10
XanoThanks! That patch only contains the removal of the old patch, unfortunately.
Comment #12
pguillard CreditAttribution: pguillard commentedThis one should be better, but tests are broken
Comment #14
dawehnerCertainly +1 for the change, the disruption is much lower than the confusion people have when dealing with the classname.
Comment #15
yched CreditAttribution: yched commentedBig +1 as well, FWIW ;-)
Comment #18
XanoRe-roll.
Comment #20
dawehnerShouldn't git be able to detect renames and so lead to MUCH smaller patches?
Comment #21
pguillard CreditAttribution: pguillard commentedI re-rolled it using git diff -M
Comment #23
joyceg CreditAttribution: joyceg commentedCan I work on this issue?
Comment #24
joyceg CreditAttribution: joyceg commentedComment #25
joyceg CreditAttribution: joyceg commentedComment #26
pguillard CreditAttribution: pguillard commented@joyceg : I guess anybody can join and help on any subject, as soon as you have red some minimum info (Just in case https://www.drupal.org/novice)
Comment #27
dawehnerPlease don't reroll but rather start from 0 and try to rename the file / class. The content of the file changed in the meantime.
Comment #28
pguillard CreditAttribution: pguillard commentedComment #29
pguillard CreditAttribution: pguillard commentedI stared from 0, and tried to find some more occurrences to replace.
Tests are still borken.
Comment #31
pguillard CreditAttribution: pguillard commentedThis one seems to be better
Comment #32
dawehnerOh yes!!
Comment #33
alexpottThis seems quite disruptive with no evaluation of why the disruption is necessary? This issue is a task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.
Comment #34
yched CreditAttribution: yched commentedre: disruption, this mostly impacts classes that extend Field / EntityField. We seem to have actually very few in core (taxo TermName, comment Depth) - and it seems those could be formatters instead ?
@dawehner: do you think there's a chance of many existing uses in contrib ?
Comment #35
dawehnerWell I hope there isn't but I have no idea.
And yes I agree, they should use formatters ideally, even if its orders of magnitude slower.
Comment #36
pguillard CreditAttribution: pguillard commentedComment #37
pguillard CreditAttribution: pguillard commentedComment #38
pguillard CreditAttribution: pguillard commentedComment #41
pguillard CreditAttribution: pguillard commented#31 rerolled
Comment #45
dawehnerMh, so why does that patch no longer apply?
Comment #46
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commented#41 rerolled
Comment #47
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedComment #50
dawehnerThe content of the actual class changed so maybe on the next reroll start again with the rename and not "just" a reroll.
Comment #51
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedreroll extended =)
Comment #52
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedComment #53
dawehner@marvin_B8
Please make a git configuration which tracks file moves ... otherwise those patches are way too big ... yeah when we would use git directly, this wouldn't be a problem in the first place at all.
Comment #54
mpdonadioThis would be a BC break at this point, correct? Or at least require an upgrade path + tests?
Comment #55
dawehnerWhat about keeping a Field.php which extends EntityField.php directly but does nothing else?
I don't see how an upgrade path would change anything? There is an advantage in using plugins, as it abstracts away the used classes, so we can switch them.
Comment #56
mpdonadioI was thinking that the `@ViewsField("field")` annotation would change, too, to match the classname. If that says the same, then an upgrade path wouldn't be needed.
Comment #57
dawehnerOh yeah that does not have to change and also doesn't
@marvin_B8
You could setup your git to detect file moving, see https://www.drupal.org/documentation/git/configure this makes the patch size smaller.
Needs work also to provide a BC layer
Comment #58
mpdonadioStarted fresh w/ a refactor by rename in PhpStorm, and a manual search of strings.
How about this for BC? Do we need to test that, at least minimally?
Comment #59
mpdonadioOK, that approach made the patch big again. It does the rename, but then changes the Field class to be
Easier to read in place.
Comment #60
dawehnerThis would be a BC break for classes extending Field at the moment
Comment #61
mpdonadioTalked w/ @dawehner briefly about this in IRC and will post a more better version tonight.
Comment #62
mpdonadioRemoved the `final`. We could also mark this as @internal, but I think the @deprecated is better since it wasn't @internal to begin with.
Comment #63
dawehnerOh that that is right, its deprecated and people should use the other class instead. Are you sure it will be removed in 8.0.x
Comment #65
xjmDiscussed with all the committers and we agreed this should be done in a minor version with BC.
Comment #68
jibranComment #70
daffie CreditAttribution: daffie commentedThe patch does not apply to drupal 8.3.
Comment #71
marvin_B8 CreditAttribution: marvin_B8 as a volunteer and at comm-press commentedreroll #62
Comment #72
dawehnerAccording to #65 this is 8.3.x eligible, nice!
Comment #73
dawehnerThis looks almost ready.
That seems unrelated
Let's ensure to put 8.3.x in there instead of 8.0.x
Add additional space here
Unused use statement
Comment #74
lomasr CreditAttribution: lomasr at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedApplied #71 patch on 8.3.x . It worked cleanly.
Comment #75
mpdonadioFeedback from #70.
Comment #76
dawehnerThank you @mpdonadio
Comment #77
lomasr CreditAttribution: lomasr at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedComment #79
catchWe should eventually trigger E_USER_DEPRECATED when the class is included, but don't have a coding standard for that for entire classes yet, so can defer that until #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases is further along.
I can't think of a better name, it's a bit confusing that the plugin is 'ViewsField' while the class is 'EntityField', but that would be another issue.
Committed/pushed to 8.3.x, thanks!