Updated: Comment #0

Problem/Motivation

After #2144327: Make all field types provide a schema() all field types could be used for entity displays if they have any widget|formatter.
Currently if field type has "configurable = TRUE" in annotation that means that field type gets the \Drupal\Core\Field\ConfigFieldItemList as default list class.
But actually that means that field items have default value widget (ConfigFieldItemListInterface) and settings form for field and instance (ConfigFieldItemInterface), but this forms cannot be accessed if we have "no_ui" in annotation.

The "no_ui" annotation is used to disallow fields to be added via field_ui module to entities, that means that this kind fields could be added in code only.

Last usage of the method should be removed in #2198917: Use the string field type for the node title field

Proposed resolution

Remove "configurable" annotation and rely on interfaces in field_ui form builders.
Replace the getConfigurableDefinitions() method with getUiDefinitions() from interface as it makes not sense anymore.

Remaining tasks

make patch,
get approvement about api clean-up
make change notice or update existing?
update https://drupal.org/node/2064123
And the review others in #2218199-9: Move email and number field types to \Drupal\Core\Field, remove modules

User interface changes

no

API changes

Removal of FieldTypePluginManagerInterface::getConfigurableDefinitions() and "configurable" setting from annotation

Comments

andypost’s picture

Status: Active » Needs review
Issue tags: +Entity Field API
andypost’s picture

Trying to remove "configurable" annotation in favor of "no_ui"
The only questionable part is FieldTypePluginManager::processDefinition() that marked by @todo
Suppose list_class should be assigned a different way, for example "class implements interface" but maybe better to re-think this automatic class assign at all, at this stage I'm not really sure about reasons for this

The last submitted patch, 1: 2191709-field-configurable-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: 2191709-field-configurable-2.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new16.85 KB

Fix last usage of "configurable" and test.
Add more robust check for field instance edit form

Status: Needs review » Needs work

The last submitted patch, 5: 2191709-field-configurable-4.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

5: 2191709-field-configurable-4.patch queued for re-testing.

Unrelated failure in \Drupal\views_ui\Tests\DisplayTest

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 536870912 bytes) in /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Database/Connection.php on line 336
andypost’s picture

The issue needs feedback and should be commited after #2191555: Allow DisplayOverviewBase use all field types or we could combine them in one

berdir’s picture

If we do this, then we have to kill the Configurable*Interface interfaces and classes too and merge whatever they do up into their parent. Otherwise you could create a non-configurable field without no_ui and it would blow up.

andypost’s picture

There's only:
ConfigFieldItemInterface - declares settings form for field and instance, going to fix
ConfigFieldItemListInterface - just declares default value forms, already fixed in patch

andypost’s picture

StatusFileSize
new3.83 KB
new20.67 KB

Fix to not "blow up" field ui.
Entity edit & view is not affected.
Let's see what bot say

amateescu’s picture

If we do this, then we have to kill the Configurable*Interface interfaces and classes too and merge whatever they do up into their parent. Otherwise you could create a non-configurable field without no_ui and it would blow up.

I had a patch for this sitting on my desktop for quite a while so I opened an issue for it: #2192259: Remove ConfigField.. Item and List classes + interfaces

berdir’s picture

Title: Remove unused FieldTypePluginManagerInterface::getConfigurableDefinitions() » Remove FieldTypePluginManagerInterface::getConfigurableDefinitions()

It's not unused, so let's remove that from the title.

andypost’s picture

StatusFileSize
new20.51 KB

re-roll

yched’s picture

So, I know there was a discussion on whether 'no_ui' and 'configurable' were redundant, but I can't really remember the arguments why both were kept :-/

Other than that, I do feel a little nervous about removing 'configurable' before we have removed the separation between "field type that can be used for configurable fields" and "field types that can only be used for base fields". Can't really point a specific reason atm, so this might just be FUD...

  1. +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php
    @@ -52,11 +52,12 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
    -      if ($definition['configurable']) {
    -        $definition['list_class'] = '\Drupal\Core\Field\ConfigFieldItemList';
    +      // Do not allow to configure a default value if "no_ui" is TRUE.
    

    How is this code (or the 'no_ui' flag) related to the notion of "default value" ?

  2. +++ b/core/lib/Drupal/Core/Field/FormatterPluginManager.php
    @@ -117,6 +117,9 @@ public function getInstance(array $options) {
    +      if (empty($field_type_definition['default_formatter'])) {
    +        return NULL;
    +      }
    

    Why is this needed ?

  3. +++ b/core/lib/Drupal/Core/Field/WidgetPluginManager.php
    @@ -103,6 +103,9 @@ public function getInstance(array $options) {
    +      if (empty($field_type_definition['default_widget'])) {
    +        return NULL;
    +      }
    

    Same, why ?

  4. +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
    @@ -137,8 +138,8 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac
    +    // Configure a default value if field implements.
    

    Unfinished sentence

yched’s picture

So, I know there was a discussion on whether 'no_ui' and 'configurable' were redundant, but I can't really remember the arguments why both were kept :-/

Quoting Berdir on IRC:

a) We still needed a way to have configurable fields that can only be added in code, that's what no_ui is for.
b) back when we made base fields use the @FieldType annotation and introduced configurable, base fields weren't ready to be used as configurable fields (no schema() etc). but amateescu's issue to drop the ConfigField* classes and interfaces it going to remove the final blocker there

So right, doing this is fine, but I still vaguely feel it would be best to do things in order here and wait for #2192259: Remove ConfigField.. Item and List classes + interfaces , but I'll defer to @amateescu.

berdir’s picture

Yes, waiting for that does make sense, agreed. Long dependency chain, but I think that's preferable in this case.

andypost’s picture

StatusFileSize
new890 bytes
new20.56 KB

I think better to make this one first because it really shows the purpose of 'configurable' definition - to provide default value widget!
#15
1) The ConfigFieldItemListInterface now only tells that field support default value widget|validate|submit. So "no_ui" means that we can't add dield and can't configure field|instance settings via Field UI.

2 and 3) when manager can't instantiate the widget or formatter plugin because there's no plugins (including default_widget|formatter) they should return nothing.

4) paraphrased: no interface means there's no default value widget (that what 'configurable' was for)

PS: in follow up we can find a better approach about how to check presence of default value widget

andypost’s picture

Issue summary: View changes

clarified this in summary

amateescu’s picture

I agree with @yched and @Berdir, it doesn't really make sense to remove 'configurable' until we remove the classes in #2192259: Remove ConfigField.. Item and List classes + interfaces. Also, hook_field_info() in D7 defined default_formatter and default_widget as non-optional, and I think we should stick with that (e.g. throw an exception if a field type doesn't declare them).

andypost’s picture

#2192259: Remove ConfigField.. Item and List classes + interfaces is in, so now we have isConfigurable() method, that could be used to check that field is configurable by
return !empty($definition['no_ui']) && empty($definition['default_widget']) && empty($definition['default_formatter'])

berdir’s picture

What I was wondering is if we should add a method on the field type manager to encapsulate *that* ? Or alternatively throw an exception for an field that does not have no_ui set but is missing a default widget or formatter?

I don't think we should make it required to have a widget and formatter for fields that can not be added in the UI, various core field types are not meant to be edited in the UI, for example the UUID (if anything, you could display it, but not edit and a read-only widget doesn't make much sense?).

andypost’s picture

StatusFileSize
new19.63 KB
new566 bytes

Re-roll with #21

EDIT discussed at IRC

<andypost> berdir, in perfect world field_ui could be able to alter field definitions so "configure" them at least default values
<andypost> berdir, seems we need to separate "configure and add"
<berdir> andypost: hm. if you look at how that function is used, there are only very few cases. there is loadFieldItems(), but I'm removing that in the entity caching issue, then there is _content_translation_form_language_content_settings_form_alter(), which I think uses it as "does this have a fieldconfig", can possibly be removed now or at least when the whole field translation stuff is done
<berdir> andypost: then there is _editor_get_processed_text_fields(), which I think is just wrong
<berdir> andypost: and field_attach_form_validate(), which is deprecated and being removed too
<andypost> berdir, that's what I'm trying to reach
<andypost> berdir, also there's access checkers for fieeld ui tabs
<berdir> andypost: in short, that means that isConfigurable() close to irrelevant, because nobody really has to care anymore if it's configurable or not
<andypost> berdir, suppose some ds module could override {entity/fields} route and allow to configure base fields (except cerdinality)
<berdir> andypost: and yes, we do need something for add, and since we don' have fields to check, something on the field type plugin manager would be more helpful
<berdir> andypost: what do you think about something like $field_type_manager->getAddableDefinitions() (method name is weird, but I assume you get the idea)

Status: Needs review » Needs work

The last submitted patch, 23: 2191709-field-configurable-22.patch, failed testing.

andypost’s picture

The things left to decide:
1) add field to entity - suppose 'no_ui' should stay for that purpose
2) allow to use field in manage form - field should have default_widget at least, but some contrib module could add widget that is not set for that field as default...
3) same for formatters - at least default_formatter is needed, otoh formatter manager could be extended with getAvailableFormatters() to make sure that field can be used in "manage display" (entityViewDisplay)
4) default values - to allow "configure" base and attached fields we need a listing of all fields (field_ui /fields route) and allow field_ui route for "edit field" to allow change label and default value

PS: suppose 4) this is a feature and could be done later or contrib

berdir’s picture

1) Yep.
2) & 3) Yes, as mentioned above, I think we should keep a function to return field types that don't have no_ui set and a default widget and formatter.
4.) That would be cool but definitely a different issue.

What we are actually doing here is remove the "configurable" flag on field types, I think that's what the issue title should be saying. We'll keep a method on the field type manager (that's my suggestion anyway), just named differently. I'm not sure what.. getUiDefinitions() getDefinitionsWithUi() getAddableDefinitions() ? No idea...

andypost’s picture

Title: Remove FieldTypePluginManagerInterface::getConfigurableDefinitions() » Remove the "configurable" flag on field types
Status: Needs work » Needs review
StatusFileSize
new9.92 KB
new26.96 KB

Trying to remove isConfigurable() method

berdir’s picture

  1. +++ b/core/modules/content_translation/content_translation.admin.inc
    @@ -102,7 +102,7 @@ function _content_translation_form_language_content_settings_form_alter(array &$
                 // translation.
                 // @todo Remove this special casing as soon as configurable and
                 //   base field definitions are "unified".
    -            if ($definition->isConfigurable() && ($field = FieldService::fieldInfo()->getField($entity_type_id, $field_name))) {
    +            if ($field = FieldService::fieldInfo()->getField($entity_type_id, $field_name)) {
                   $instance = FieldService::fieldInfo()->getInstance($entity_type_id, $bundle, $field_name);
                   $form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
                     '#label' => $instance->getLabel(),
    

    Hm, you should be able to drop all this, because $definition *is* already the instance, and should therefore have the correct label.

  2. +++ b/core/modules/field/field.deprecated.inc
    @@ -335,8 +335,7 @@ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langc
       $has_violations = FALSE;
       foreach ($entity as $field_name => $field) {
    -    $definition = $field->getFieldDefinition();
    -    if ($definition->isConfigurable() && (empty($options['field_name']) || $options['field_name'] == $field_name)) {
    +    if (empty($options['field_name']) || $options['field_name'] == $field_name) {
           $field_violations = $field->validate();
           if (count($field_violations)) {
             $has_violations = TRUE;
    

    I'd expect this check to go away in https://drupal.org/node/2095195, if not already, then it probably should.

Status: Needs review » Needs work

The last submitted patch, 28: 2191709-field-configurable-28.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.95 KB
new25.73 KB

Fix merge error and use renamed function in hook_help()

Status: Needs review » Needs work

The last submitted patch, 31: 2191709-field-configurable-31.patch, failed testing.

andypost’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new4.3 KB
new27.42 KB

#31 is a broken bot
new patch should fix left failures caused by entity cache, that should be fixed by #597236: Add entity caching to core

the only place to use getUiDefinitions() in field_help() now, that could be replaced with inline filtering

andypost’s picture

Issue summary: View changes
berdir’s picture

Status: Needs review » Needs work

Needs a re-roll due to email/number but looks great.

  1. +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php
    @@ -39,11 +39,11 @@ public function getDefaultInstanceSettings($type);
     
       /**
    -   * Gets the definition of all field types that are configurable.
    +   * Gets the definition of all field types that could be added via UI.
        *
    

    ... that can be added... I think.

  2. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php
    @@ -18,7 +18,7 @@
      *   label = @Translation("E-mail"),
      *   description = @Translation("An entity field containing an e-mail value."),
    - *   configurable = FALSE,
    + *   no_ui = TRUE,
      *   default_widget = "string",
    

    EmailItem has been merged, so no longer no_ui :)

  3. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/FloatItem.php
    @@ -18,7 +18,7 @@
      *   label = @Translation("Float"),
      *   description = @Translation("An entity field containing an float value."),
    - *   configurable = FALSE
    + *   no_ui = TRUE
    
    +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php
    @@ -18,7 +18,7 @@
      *   label = @Translation("Integer"),
      *   description = @Translation("An entity field containing an integer value."),
    - *   configurable = FALSE
    + *   no_ui = TRUE
      * )
    

    Same.

  4. +++ b/core/modules/content_translation/content_translation.admin.inc
    @@ -102,7 +102,7 @@ function _content_translation_form_language_content_settings_form_alter(array &$
                 // translation.
                 // @todo Remove this special casing as soon as configurable and
                 //   base field definitions are "unified".
    -            if ($definition->isConfigurable() && ($field = FieldService::fieldInfo()->getField($entity_type_id, $field_name))) {
    +            if ($field = FieldService::fieldInfo()->getField($entity_type_id, $field_name)) {
                   $instance = FieldService::fieldInfo()->getInstance($entity_type_id, $bundle, $field_name);
                   $form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
                     '#label' => $instance->getLabel(),
    

    $definition === $instance already, so you can remove this part completely.

  5. +++ b/core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php
    diff --git a/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
    index f325b85..c10a477 100644
    
    index f325b85..c10a477 100644
    --- a/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
    
    --- a/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
    +++ b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
    
    +++ b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
    +++ b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
    @@ -127,33 +127,26 @@ function testProcessedCache() {
    
    @@ -127,33 +127,26 @@ function testProcessedCache() {
         // data.
    

    This was only necessar due to the entity cache change, it should no longer be needed. I'd suggest to remove it to avoid conflicts with the entity cache patch.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new2.96 KB
new26.19 KB

Fixed 1-4, for #4 just added check for interface because solving @todo is out of scope the issue

About #5 (patch also contains a hunk from #2218219: _editor_get_processed_text_fields() should search text_processing only in text fields)

+++ b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
@@ -127,33 +127,26 @@ function testProcessedCache() {
-    $this->assertEqual($cache->data, array(
-      Language::LANGCODE_NOT_SPECIFIED => array(
-        'summary_field' => array(
-          0 => array(
...
+    $this->assertEqual($cache->data[Language::LANGCODE_NOT_SPECIFIED]['summary_field'], array(
+      0 => array(

This still needed, because with a patch entities are cached with all fields.

berdir’s picture

This still needed, because with a patch entities are cached with all fields

No they are not, they were at one point but we changed that back because it caused a bunch of other test fails. Try it, it should pass just fine without that change.

Agree on the @todo in content_translation, didn't see all of it, that's something for #2143291: Clarify handling of field translatability.

This looks ready to me, but a review from one of the field API maintainers would be nice.

andypost’s picture

Related issues: +#2143291: Clarify handling of field translatability
StatusFileSize
new2.12 KB
new24.07 KB

So removed the hunk in text tests

andypost’s picture

Let's see how many failures could be if we remove #15 (2-3) hunk

Also re-roll patch after #2181549: Provide a StringLong field item with schema type 'text' without a 'format' column.

andypost’s picture

Seems something was fixed in core so "no-null" is passed!
@yched any more left?

andypost’s picture

Issue tags: +Field API
StatusFileSize
new23.28 KB
swentel’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I asked Berdir for some more information on this, since I wasn't totally grokking the purpose of this patch from the issue summary.

Basically, back when we had both "base" fields and "configurable" fields, this distinction made sense. But over time, we've settled on all fields deriving from the same "base" type. Now, "not-configurable" doesn't make sense as a separate distinction, because if all you want to do is prevent a field from being configured in the UI, you can use the existing no_ui property for that.

Therefore...

Committed and pushed to 8.x. Thanks!

  • Commit b907c2f on 8.x by webchick:
    Issue #2191709 by andypost, Berdir: Remove the configurable flag on...
andypost’s picture

yched’s picture

Title: Remove the "configurable" flag on field types » [Followup] Remove the "configurable" flag on field types
Status: Fixed » Needs review
StatusFileSize
new598 bytes
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php
@@ -21,7 +21,7 @@
- *   configurable = FALSE,
+ *   no_ui = TRUE,

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php
@@ -16,7 +16,7 @@
- *   configurable = FALSE
+ *   no_ui = FALSE

The second one looks like a mistake ?

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Sure, merge typo

swentel’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.42 KB
new1.84 KB
new40.69 KB

We actually forgot a couple more

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Drop is moving

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed that to 8.x, too.

  • Commit 1869810 on 8.x by webchick:
    Issue #2191709 by andypost, swentel, yched: [Followup] Remove the...
andypost’s picture

Title: [Followup] Remove the "configurable" flag on field types » Remove the "configurable" flag on field types

Fix title

Status: Fixed » Closed (fixed)

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