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.

Files: 
CommentFileSizeAuthor
#22 field-ui-prefix-settings.patch1.04 KBtstoeckler
PASSED: [[SimpleTest]]: [MySQL] 57,991 pass(es).
[ View ]
#19 1393094-19.patch5.69 KBswentel
PASSED: [[SimpleTest]]: [MySQL] 57,665 pass(es).
[ View ]
#19 interdiff.txt604 bytesswentel
#16 1393094-16.patch5.71 KBswentel
PASSED: [[SimpleTest]]: [MySQL] 56,182 pass(es).
[ View ]
#10 1393094-10.patch5.53 KBswentel
PASSED: [[SimpleTest]]: [MySQL] 55,544 pass(es).
[ View ]
#10 interdiff.txt2 KBswentel
#8 1393094-9.patch3.53 KBswentel
PASSED: [[SimpleTest]]: [MySQL] 55,661 pass(es).
[ View ]
#5 1393094-remove-field-prefix.patch1.4 KBsolotandem
FAILED: [[SimpleTest]]: [MySQL] 34,372 pass(es), 25 fail(s), and 8 exception(es).
[ View ]
#5 1393094-remove-field-prefix-D7.patch1.37 KBsolotandem
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1393094-remove-field-prefix-D7_0.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#1 1393094-remove-field-prefix.patch1.37 KBsolotandem
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1393094-remove-field-prefix.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
#1 1393094-remove-field-prefix-D7.patch1.4 KBsolotandem
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1393094-remove-field-prefix-D7.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new1.4 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1393094-remove-field-prefix-D7.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
new1.37 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1393094-remove-field-prefix.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

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.

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

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

Status:Needs work» Needs review
StatusFileSize
new1.37 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1393094-remove-field-prefix-D7_0.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
new1.4 KB
FAILED: [[SimpleTest]]: [MySQL] 34,372 pass(es), 25 fail(s), and 8 exception(es).
[ View ]

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.

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

Title:Remove arbitrary "field_" prefix from fields created through UIMake the field prefix in Field ui configurable
Category:feature» task
Status:Needs work» Needs review
Issue tags:+Field API
StatusFileSize
new3.53 KB
PASSED: [[SimpleTest]]: [MySQL] 55,661 pass(es).
[ View ]

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.

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

StatusFileSize
new2 KB
new5.53 KB
PASSED: [[SimpleTest]]: [MySQL] 55,544 pass(es).
[ View ]

I guess yeah, here it is :)

Status:Needs review» Reviewed & tested by the community

Yihaa!

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_

Why would that break existing fields?

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.

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.

StatusFileSize
new5.71 KB
PASSED: [[SimpleTest]]: [MySQL] 56,182 pass(es).
[ View ]

Needed a reroll.

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()?

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

Status:Needs work» Needs review
StatusFileSize
new604 bytes
new5.69 KB
PASSED: [[SimpleTest]]: [MySQL] 57,665 pass(es).
[ View ]

Changed the update function.

Status:Needs review» Reviewed & tested by the community

Ok another try :). Thnx alex!

Status:Reviewed & tested by the community» Fixed

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

Status:Fixed» Needs review
StatusFileSize
new1.04 KB
PASSED: [[SimpleTest]]: [MySQL] 57,991 pass(es).
[ View ]

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.

Status:Needs review» Reviewed & tested by the community

Makes sense to me.

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.

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.

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: Tour integration for Field UI module

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.