Problem/Motivation

field_ ... every Drupal person knows, this is a configurable field. I question now though this behaviour. An entity consists of fields, and each has a name. This is the message we should really communicate.

Do we want to drop it?
What does this mean from a community perspective?

Advantages

  • This would automatically make our REST support better, as there is less Drupalism involved.

Disadvantages

  • A decade of people with experience about it.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 2846872-2.patch351 bytesdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Issue summary: View changes
FileSize
351 bytes

This is set to active due to the required discussion.

cilefen’s picture

+1 It is redundant.

dawehner’s picture

Issue summary: View changes

Add expanded the issue summary a tiny little bit. I guess we could discuss that still way better.

Berdir’s picture

Hm. I often *change* it to something else, but I think having some sort of prefix makes sense.

We have protection against conflicts with base fields, but you never know what will be added in the future. Having a prefix limits the risk of ever running into a conflict when an entity type gets a new base field, either by itself or anotherm module.

I also use it in our install profile to set it to np8_, and then change it on projects to something project-specific, so I can add more np8_* fields later on without risk of conflict. That's still possible, but by not having a default, people might by less likely to think of that?

This will also break *tons* of tests that currently create fields with e.g. fieldUIAddNewField() and then somehow assert or access that field.

Counter-Proposal: Expose it in the UI, with a recommendation to have a prefix but sites that don't want one can remove it, on their own risk.

lslinnet’s picture

How will "This would automatically make our REST support better, as there is less Drupalism involved." be achieved by removing the "field_" prefix? based on what standard will this name change make the REST support better?

yched’s picture

As @Berdir points, the intent of the prefix is to allow a core / contrib entity type to add new base fields in any minor / major release without fearing it will clash somewhere with someone's configurable fields (and possibly with supporting business logic around $entity->field_foobar in custom code)

Granted, the specific 'field_‘ string litteral was picked at a time when the non-'field_' things in an entity were not fields...
Today that string is less relevant as a differenciator. But the point of having *some* prefix remains.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

e0ipso’s picture

the intent of the prefix is to allow a core / contrib entity type to add new base fields in any minor / major release without fearing it will clash somewhere with someone's configurable fields

I think that that highlights that this protection is brittle, since it will still clash somewhere with someone's base fields. One could argue that to avoid collisions field IDs should not be human generated. I get that even if it was a good idea to have machine generated field IDs (there are several pretty obvious drawbacks) it's too late for that implementation.

However I think that this highlights how we are acknowledging some level of conflicts. I think that if we drop the prefix we'll only have potential conflicts when core is adding a base field, since field machine names are ensured to be unique when configuring a field.

My question is: is that marginal increase on risk worth keeping the prefix?

Wim Leers’s picture

e0ipso’s picture

Status: Active » Closed (won't fix)

Now that we have JSON API Extras and #2846488: Explore abstracting away "Drupalisms", we can close this. Thanks Wim for bringing it up.

gabesullice’s picture

Version: 8.4.x-dev » 9.x-dev
Status: Closed (won't fix) » Active
Issue tags: +API-First Initiative

I think it's worth considering this again, perhaps in the context of Drupal 9.

When Drupal is used in an API-first context, the distinction between a machine name and a field label gets blurred since the machine name might be exposed to 3rd party developers who are not the developers of the Drupal site itself.

The GraphQL and JSON:API modules both have workarounds for this, but the DX/site builder experience could be improved if the field name that is exposed via their public APIs were configurable in Drupal core (perhaps on the field config page).

Since it wasn't already mentioned explicitly, I'll call it out: Snake case is not at all the idiomatic style in JavaScript or JSON-based APIs. It's almost universally lower camel case.

ifrik’s picture

My question is: is that marginal increase on risk worth keeping the prefix?

An example anecdote where it can break things.
I have a site that was migrated from D6 to D7 and then D8. This resulted in a field on the user account with the field name "homepage".
Anonymous users could no access node pages while logged-in users could.
template_preprocess_username accesses a property $account->homepage, not sure why something to do with comments maybe in the past. The content of $account->homepage is certainly not expected to be a field object.

Version: 9.x-dev » 9.0.x-dev

The 9.0.x branch will open for development soon, and the placeholder 9.x branch should no longer be used. Only issues that require a new major version should be filed against 9.0.x (for example, removing deprecated code or updating dependency major versions). New developments and disruptive changes that are allowed in a minor version should be filed against 8.9.x, and significant new features will be moved to 9.1.x at committer discretion. For more information see the Allowed changes during the Drupal 8 and 9 release cycles and the Drupal 9.0.0 release plan.

xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev

We'd need to figure out a way to make this BC with an upgrade path. Since it's only the default for new things, it can be done in a minor, but we'd need to make sure we're not breaking existing assumptions.

Since 8.9.x and 9.0.x are now in beta, I'm moving this to 9.1.x. Thanks!

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.