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 to EntityField
  • Provide a BC layer

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#75 interdiff-70-75.txt1.53 KBmpdonadio
#75 2408667-75.patch59.03 KBmpdonadio
#74 rename.png95.27 KBlomasr
#71 rename_field_php_to-2408667-70.patch59.58 KBmarvin_B8
#62 interdiff-58-62.txt497 bytesmpdonadio
#62 rename_field_php_to-2408667-62.patch56.24 KBmpdonadio
#58 rename_field_php_to-2408667-58.patch56.25 KBmpdonadio
#51 2408667-51.patch87.81 KBmarvin_B8
#51 interdiff-2408667-46-51.txt578 bytesmarvin_B8
#46 interdiff-2408667-41-46.txt73.24 KBmarvin_B8
#46 views_rename_field_to_entityfield-2408667-46.patch87.8 KBmarvin_B8
#41 views_rename_field_to_entityfield-2408667-41.patch18.56 KBpguillard
#31 interdiff-2408667-29-31.txt1.17 KBpguillard
#31 views_rename_field_to_entityfield-2408667-31.patch18.55 KBpguillard
#29 views_rename_field_to_entityfield-2408667-29.patch17.61 KBpguillard
#21 drupal_2408667_21.patch35.83 KBpguillard
#18 drupal_2408667_18.patch81.57 KBXano
#12 views_rename_field_to_entityfield-2408667-12.patch35.88 KBpguillard
#9 views_rename_field_to_entityfield-2408667-9.patch45.75 KBpguillard
#5 views_rename_field_to_entityfield-2408667-5.patch81.34 KBgeertvd
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

+ 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.

dawehner’s picture

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.

I'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.

yched’s picture

our coding standard is just bullshit, many people disagreed with it in a long long time

Aw. 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 :-)

jibran’s picture

geertvd’s picture

geertvd’s picture

Status: Active » Needs review
Xano’s picture

Status: Needs review » Needs work

Could you please roll another patch using git diff -M, so the rename is marked as a change, rather than a deletion+new file?

pguillard’s picture

Assigned: Unassigned » pguillard
pguillard’s picture

Assigned: pguillard » Unassigned
Status: Needs work » Needs review
FileSize
45.75 KB

I 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)

Xano’s picture

Status: Needs review » Needs work

Thanks! That patch only contains the removal of the old patch, unfortunately.

The last submitted patch, 9: views_rename_field_to_entityfield-2408667-9.patch, failed testing.

pguillard’s picture

Status: Needs work » Needs review
FileSize
35.88 KB

This one should be better, but tests are broken

Status: Needs review » Needs work

The last submitted patch, 12: views_rename_field_to_entityfield-2408667-12.patch, failed testing.

dawehner’s picture

Certainly +1 for the change, the disruption is much lower than the confusion people have when dealing with the classname.

yched’s picture

Big +1 as well, FWIW ;-)

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: views_rename_field_to_entityfield-2408667-12.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
81.57 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 18: drupal_2408667_18.patch, failed testing.

dawehner’s picture

Shouldn't git be able to detect renames and so lead to MUCH smaller patches?

pguillard’s picture

Status: Needs work » Needs review
FileSize
35.83 KB

I re-rolled it using git diff -M

Status: Needs review » Needs work

The last submitted patch, 21: drupal_2408667_21.patch, failed testing.

joyceg’s picture

Can I work on this issue?

joyceg’s picture

Assigned: Unassigned » joyceg
joyceg’s picture

Assigned: joyceg » Unassigned
pguillard’s picture

@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)

dawehner’s picture

I re-rolled it using git diff -M

Please don't reroll but rather start from 0 and try to rename the file / class. The content of the file changed in the meantime.

pguillard’s picture

Assigned: Unassigned » pguillard
pguillard’s picture

Status: Needs work » Needs review
FileSize
17.61 KB

I stared from 0, and tried to find some more occurrences to replace.
Tests are still borken.

Status: Needs review » Needs work

The last submitted patch, 29: views_rename_field_to_entityfield-2408667-29.patch, failed testing.

pguillard’s picture

This one seems to be better

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Oh yes!!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs beta evaluation

This 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.

yched’s picture

re: 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 ?

dawehner’s picture

@dawehner: do you think there's a chance of many existing uses in contrib ?

Well 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.

pguillard’s picture

Issue summary: View changes
pguillard’s picture

Issue summary: View changes
pguillard’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 31: views_rename_field_to_entityfield-2408667-31.patch, failed testing.

pguillard’s picture

Status: Needs work » Needs review
FileSize
18.56 KB

#31 rerolled

Status: Needs review » Needs work

The last submitted patch, 41: views_rename_field_to_entityfield-2408667-41.patch, failed testing.

The last submitted patch, 41: views_rename_field_to_entityfield-2408667-41.patch, failed testing.

dawehner’s picture

Mh, so why does that patch no longer apply?

marvin_B8’s picture

marvin_B8’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 46: views_rename_field_to_entityfield-2408667-46.patch, failed testing.

The last submitted patch, 46: views_rename_field_to_entityfield-2408667-46.patch, failed testing.

dawehner’s picture

The content of the actual class changed so maybe on the next reroll start again with the rename and not "just" a reroll.

marvin_B8’s picture

reroll extended =)

marvin_B8’s picture

Status: Needs work » Needs review
dawehner’s picture

@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.

mpdonadio’s picture

This would be a BC break at this point, correct? Or at least require an upgrade path + tests?

dawehner’s picture

What about keeping a Field.php which extends EntityField.php directly but does nothing else?

This would be a BC break at this point, correct? Or at least require an upgrade path + tests?

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.

mpdonadio’s picture

I 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.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +rc target triage

I 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.

Oh yeah that does not have to change and also doesn't

+ *
+ * @ViewsField("field")
+ */
+class EntityField extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface {
+  use 

@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

mpdonadio’s picture

Status: Needs work » Needs review
FileSize
56.25 KB

Started 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?

mpdonadio’s picture

OK, that approach made the patch big again. It does the rename, but then changes the Field class to be

<?php

/**
 * @file
 * Contains \Drupal\views\Plugin\views\field\Field.
 */

namespace Drupal\views\Plugin\views\field;

use Drupal\views\Plugin\views\field\EntityField;

/**
 * A stub class to provide backward compatibility for EntityField.
 *
 * @deprecated in Drupal 8.0.x and will be removed before 9.0.0
 *  Use \Drupal\views\Plugin\views\field\EntityField instead.
 */
final class Field extends EntityField {

}

Easier to read in place.

dawehner’s picture

This would be a BC break for classes extending Field at the moment

mpdonadio’s picture

Assigned: pguillard » mpdonadio

Talked w/ @dawehner briefly about this in IRC and will post a more better version tonight.

mpdonadio’s picture

Removed the `final`. We could also mark this as @internal, but I think the @deprecated is better since it wasn't @internal to begin with.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Oh 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

The last submitted patch, 51: 2408667-51.patch, failed testing.

xjm’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Postponed
Issue tags: -Needs beta evaluation, -rc target triage +minor version target

Discussed with all the committers and we agreed this should be done in a minor version with BC.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

Status: Postponed » Needs work

The last submitted patch, 62: rename_field_php_to-2408667-62.patch, failed testing.

dawehner’s picture

According to #65 this is 8.3.x eligible, nice!

dawehner’s picture

Issue summary: View changes

This looks almost ready.

  1. +++ b/core/modules/views/src/Plugin/views/field/EntityField.php
    @@ -629,8 +627,8 @@ public function buildGroupByForm(&$form, FormStateInterface $form_state) {
         $group_columns = array(
    -      'entity_id' => $this->t('Entity ID'),
    -    ) + array_map('ucfirst', array_combine($field_columns, $field_columns));
    +        'entity_id' => $this->t('Entity ID'),
    +      ) + array_map('ucfirst', array_combine($field_columns, $field_columns));
    

    That seems unrelated

  2. +++ b/core/modules/views/src/Plugin/views/field/Field.php
    @@ -2,1074 +2,14 @@
    + * @deprecated in Drupal 8.0.x and will be removed before 9.0.0
    

    Let's ensure to put 8.3.x in there instead of 8.0.x

  3. +++ b/core/modules/views/src/Plugin/views/field/Field.php
    @@ -2,1074 +2,14 @@
    + *  Use \Drupal\views\Plugin\views\field\EntityField instead.
    

    Add additional space here

+++ b/core/modules/views/src/Plugin/views/field/Field.php
@@ -2,1074 +2,14 @@
+use Drupal\views\Plugin\views\field\EntityField;

Unused use statement

lomasr’s picture

FileSize
95.27 KB

Applied #71 patch on 8.3.x . It worked cleanly.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
FileSize
59.03 KB
1.53 KB

Feedback from #70.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @mpdonadio

lomasr’s picture

  • catch committed bf42d73 on 8.3.x
    Issue #2408667 by pguillard, mpdonadio, marvin_B8, Xano, geertvd, lomasr...
catch’s picture

Status: Reviewed & tested by the community » Fixed

We 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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.