Problem/Motivation

If there is some use case or justification for the "field_" prefix on fields created through the UI, please let me know. Otherwise, it seems unnecessary. Fields can be created programmatically without the prefix and they, of course, work fine.

This could be ported to 7.x as well.

Proposed resolution

Remove the "field_" prefix in field_ui.admin.inc.

Remaining tasks

Tests should continue to work; no documentation.

User interface changes

None.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

solotandem’s picture

Status: Active » Needs review
FileSize
1.4 KB
1.37 KB

Attached patches implement the proposed resolution for Drupal 8 and 7.

Status: Needs review » Needs work

The last submitted patch, 1393094-remove-field-prefix.patch, failed testing.

joachim’s picture

> If there is some use case or justification for the "field_" prefix on fields created through the UI, please let me know.

My assumption (and it's only that) is that this guarantees against clashing with any fields that are defined by modules.
Also, it means you can easy tell which ones are user-created.

boombatower’s picture

Yes, that was my guess to. Our use-case is that people create fields in UI and export using features and such to become "coded" fields and given that the field length is restricted in length field_ is rather wasteful.

Patches are backwards (d7 = d8, etc).

solotandem’s picture

Status: Needs work » Needs review
FileSize
1.37 KB
1.4 KB

Oops. I named the patch files opposite their core versions.

Status: Needs review » Needs work

The last submitted patch, 1393094-remove-field-prefix.patch, failed testing.

Barry_Fisher’s picture

As a sidenote, I've created a D7 module that removes the field_ prefix from being added in the Field UI. Basically it overrides the validate functionality and alters the field ui overview form accordingly. May be useful to anyone landing on this post as I did and needed a quick fix workaround.

http://drupal.org/project/field_name_prefix_remove

swentel’s picture

Title: Remove arbitrary "field_" prefix from fields created through UI » Make the field prefix in Field ui configurable
Category: feature » task
Status: Needs work » Needs review
Issue tags: +Field API
FileSize
3.53 KB

So how about we make this configurable with our shiny new configuration system in core ?
No UI to configure this, but it's easy to move this into staging, change it and then import - or use 'drush cedit field_ui.settings' to change to what you like.

aspilicious’s picture

I like it, but we need a test to verify changing a prefix actually works :)

swentel’s picture

FileSize
2 KB
5.53 KB

I guess yeah, here it is :)

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Yihaa!

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Hmmm... I'm not sure about this change basically because changing this after you create a field will totally break your site. Either fields created by the field ui have field_ not... but making this configurable seems open cans of worms. Personally I think all field names should be namespaced by the module that creates them... so actually I'm arguing that we want field_

aspilicious’s picture

Why would that break existing fields?

stijndm’s picture

Great stuff. Good idea to have it as a hidden setting.

@alexpott I'm not sure how this will break existing fields as this settings is only used when a new field is created.

As for the namespacing issue, I feel there is enough argument to make this configurable. People working on distributions or features might want to namespace their fields according to the content type or feature they are building. Having field_ automatically prefixed eats into the character limit making it more difficult to have proper field naming, sometimes resulting in the use of arbitrary and meaningless abbreviations.

The average Drupal user/configurator will never know of the existence of this setting keeping all their fields namespaced within the field module. While power users have some extra flexibility.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

@alexpott This won't break existing fields in any way. This is just the prefix when you are creating a new field, after that nothing can go wrong anymore.

I've talked this through with yched at DrupalCon and he was ok with it, also since it's a hidden setting. We'll document it of course, but there will be no UI in core that allows you to change this. This is a power user configuration option, which people have been wanting for a while already anyway.

Setting to RTBC for now.

swentel’s picture

FileSize
5.71 KB

Needed a reroll.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/field_ui/field_ui.installundefined
@@ -43,3 +43,14 @@ function field_ui_update_8001() {
+function field_ui_update_8002() {
+  update_variables_to_config('field_ui.settings', array(
+    'field_prefix' => 'field_prefix',
+  ));

This looks weird... does the field_prefix variable exist in Drupal 7? Perhaps you want to use update_7_to_8_install_default_config()?

swentel’s picture

Ah, no it doesn't exist, good to know :)

swentel’s picture

Status: Needs work » Needs review
FileSize
604 bytes
5.69 KB

Changed the update function.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Ok another try :). Thnx alex!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 097303e and pushed to 8.x. Thanks!

tstoeckler’s picture

Status: Fixed » Needs review
FileSize
1.04 KB

Can we add a little snippet to default.settings.php that informs people about this? I'm not entirely sure if we're 100% consistent with that currently but I do think it is a common pattern to do this, and one I think makes sense.

If someone disagrees or in general thinks this should be a separate issue, no problem, I just thought this is pretty unproblematic.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/sites/default/default.settings.phpundefined
@@ -629,6 +629,19 @@
+#$conf['field_ui.settings']['field_prefix'] = '';

This should have the default value to be consistent with the other sections...

Also I'm not sure this is really required as in reality we should be encouraging people to change this in their config... if we want to only manage this here then it should move out of CMI into Settings.

tstoeckler’s picture

Re #24: That's true, but the question then is, how will people know about this at all? I don't think when people will someday download Drupal 8.0 that they will open up every single config file to see what they can configure.

swentel’s picture

We could create a change notice I guess ? That's fine for me as well. This is not settings indeed.

Maybe we can include this in the tour integration for Field UI ? #1960824: Write tour integration for Field UI module

swentel’s picture

Status: Needs work » Fixed

Created a change notice, that's good enough for me imo.

See https://drupal.org/node/2060489

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

solotandem’s picture

For those that want to see this back ported to D7, attached is a rerolled patch that works with recent releases of D7, including 7.28.

Not changing the version; if there is traction to back port, then this can be done or a new issue created and referenced here.

dstorozhuk’s picture

Hello, that is weird, but settings the $conf['field_ui.settings']['field_prefix'] = 'f_'; doesn't make any effect.

I also tried to change the 'field_prefix' in path/to/my/sync/field_ui.settings.yml and still have no luck.

Does somebody has the same issue.

PS. other settings could be controlled fine from settings.php or changing configs in path/to/my/sync/.

markconroy’s picture

@dstorozhuk (sorry, I know you probably have this fixed by now, but just for others who come here)

You need to use
$config['field_ui.settings']['field_prefix'] = 'f_'
not
$conf['field_ui.settings']['field_prefix'] = 'f_'.