Updated: Comment #0

Problem/Motivation

Currently "manage view" and "manage form display" are limited to "configurable" field types
But there's a set of Core\Field\* field types that can't be re-used because they are not configurable

Proposed resolution

Allow this screens to manage all field types, allow to configure fields for #2010930: [META] Apply formatters and widgets to rendered entity base fields (all besides node.title)

Remaining tasks

just need to find a way to display fields that have no allowed formatter/widget

User interface changes

more fields to configure

API changes

no

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Title: AllowDisplayOverviewBase use all field types » Allow DisplayOverviewBase use all field types
Issue summary: View changes
Issue tags: +Entity Field API
andypost’s picture

Status: Active » Needs review
yched’s picture

Status: Needs review » Reviewed & tested by the community

Yes, that's an omission from #2144919: Allow widgets and formatters for base fields to be configured in Field UI.
It worked so far because node.title is still the only base field that uses widgets / formatters, and it uses 'text' field type, which happens to be "configurable".

Berdir’s picture

I was a bit confused what this actually does, but apparently it is only used to read the default widget and formatter from the field type info right now? So should't have any visible affect until we actually start adding widgets and formatters to more base fields. There's also not much that could be tested due to that...

yched’s picture

Yes, earlier on, the "Manage fields" page was a subclass of DisplayOverviewBase, and it used $this->fieldTypes to build the list of available field types for the "add new field" UI. Thus, it had to be limited to "configurable field types".

That's not the case anymore, and DisplayOverviewBase::$fieldTypes has a much narrower use now. And yes, that use now covers all field types, not just "configurable" ones.

webchick’s picture

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

Needs test coverage, IMO. While we might get some anecdotal test coverage out of #2144919: Allow widgets and formatters for base fields to be configured in Field UI, this is part of the base field API, so we should be able to validate it independently.

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
2.5 KB
3.21 KB

Here is a test

andypost’s picture

The last submitted patch, 7: 2191555-base-fields_in_field-ui-7.patch, failed testing.

The last submitted patch, 7: 2191555-base-fields_in_field-ui-7-fail.patch, failed testing.

yched’s picture

+++ b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module
@@ -4,3 +4,12 @@
+function field_ui_test_field_info_alter(&$info) {
+  // Let the string field type to re-use an existing formatter and widget.
+  $info['string']['default_formatter'] = 'text_plain';
+  $info['string']['default_widget'] = 'text_textfield';
+}

Honestly, I'd rather not do that.

This can't be tested right now because no widgets / formatters exist ATM that can be applied to field types that are not also "configurable fields types". Historically, only "Field API fields" have widgets & formatters, and currently that's still the case.

That will change at some point, but right now I'd rather not introduce weird / artificial alters in a test module to create conditions we don't have. It only makes the test suite harder to maintain.

@webchick : I'd ask to reconsider committing the fix alone.

Status: Needs review » Needs work

The last submitted patch, 8: 2191555-base-fields_in_field-ui-8.patch, failed testing.

The last submitted patch, 8: 2191555-base-fields_in_field-ui-8-fail.patch, failed testing.

The last submitted patch, 8: 2191555-base-fields_in_field-ui-8-fail.patch, failed testing.

andypost’s picture

Remove unused changes in entity_test, just more alters. Agree with @yched but otoh we could re-use this code and test latter

The following change is needed to properly test field admin tabs

+++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestBaseFieldDisplay.php
@@ -32,8 +32,8 @@
- *     "edit-form" = "entity_test.edit_entity_test",
- *     "admin-form" = "entity_test.admin_entity_test"
+ *     "edit-form" = "entity_test.edit_entity_test_base_field_display",
+ *     "admin-form" = "entity_test.admin_entity_test_base_field_display"

This is needed to not duplicate tabs for field ui (bug introduced in #2144919: Allow widgets and formatters for base fields to be configured in Field UI

The last submitted patch, 15: 2191555-base-fields_in_field-ui-12-fail.patch, failed testing.

The last submitted patch, 15: 2191555-base-fields_in_field-ui-12-fail.patch, failed testing.

andypost’s picture

@berdir suggested fix in IRC, let's see what bot say

Status: Needs review » Needs work

The last submitted patch, 18: 2191555-base-fields_in_field-ui-16.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
Berdir’s picture

+++ b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.module
@@ -4,3 +4,32 @@
+ */
+function field_ui_test_field_info_alter(&$info) {
+  // Let the string field type to re-use an existing formatter and widget.
+  $info['string']['default_formatter'] = 'text_plain';
+  $info['string']['default_widget'] = 'text_textfield';
+}
+

I have still no idea why we're not doing this by default, in text.module :)

node.title uses text just to have a formatter/widget but that means it also has a format in the schema, which will get in the way when trying to generate the schema.

But certainly better already, if we can make it work.

andypost’s picture

@Berdir we can't because first we need to unify constraints, that happens in #2002168: Convert form validation of terms to entity validation now

yched’s picture

+/**
+ * Implements hook_field_info_alter().
+ */
+function field_ui_test_field_info_alter(&$info) {
+  // Let the string field type to re-use an existing formatter and widget.
+  $info['string']['default_formatter'] = 'text_plain';
+  $info['string']['default_widget'] = 'text_textfield';
+}
+
+/**
+ * Implements hook_field_formatter_info_alter().
+ */
+function field_ui_test_field_formatter_info_alter(&$info) {
+  // Allow formatter for the string field type.
+  if (isset($info['text_plain'])) {
+    $info['text_plain']['field_types'][] = 'string';
+  }
+}
+
+/**
+ * Implements hook_field_widget_info_alter().
+ */
+function field_ui_test_field_widget_info_alter(&$info) {
+  // Allow widget for the string field type.
+  if (isset($info['text_textfield'])) {
+    $info['text_textfield']['field_types'][] = 'string';
+  }
+}

As stated earlier, I'd really rather avoid adding those here. This is not the issue for that. If we want to make those widgets / formatters run on 'string' fields, that's a separate issue.

Still +1 on committing the fix alone.

Berdir’s picture

The issue in #23 has been committed, but ok yes, let's either get the fix in without test coverage instead of altering something to together *or* close the issue, create a new one to make node.title and the test entity use string, make sure that it works and as part of that, fix the bug here.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

So I'm hidding all patches except #0

alexpott’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Berdir’s picture

See #2198917: Use the string field type for the node title field, based on this issue, I'd expect that to fail because of this bug, so let's see what happens.