Follow up from #1950632: Create a FieldDefinitionInterface and use it for formatters and widgets. If code isn't specifically working with configuring Field API fields and instances (e.g., providing settings forms), then it has no business dealing with those objects/interfaces directly, and should instead interact only via FieldDefinitionInterface. That allows future core or contrib code to pass in nonconfigurable fields and still have everything work.

This doesn't fix all of core to do this, but does the parts that were found in the course of #1988612: Apply formatters and widgets to rendered entity base fields, starting with node.title. Extracting this part because it's an API change, so would be good to have land before API freeze, but the rest of that issue requires more work and review.

Because this includes changes to the getConstraints() methods of text field type classes, it also removes that method from TextWithSummaryItem and TextItemBase, and leaves it only on TextItem, since that is the only type that actually provides a max_length setting.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

+++ b/core/lib/Drupal/Core/Entity/Field/Field.php
@@ -51,6 +51,14 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface
+  public function getFieldDefinition() {
+    // @todo https://drupal.org/node/1988612
+    return NULL;
+  }

I think this might be the only controversial part of this patch. The implementation of a nonconfigurable field definition class is still under discussion in #1988612-40: Apply formatters and widgets to rendered entity base fields, starting with node.title, but I still think it makes sense to add the interface for field types to be able to get their definition in this issue, since that's part of the API change being made here.

Berdir’s picture

+++ b/core/lib/Drupal/Core/Entity/Field/FieldInterface.phpundefined
@@ -28,6 +28,13 @@
+   * @return \Drupal\Core\Entity\Field\FieldDefinitionInterface

+++ b/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.phpundefined
@@ -24,6 +24,13 @@
+   * @return \Drupal\Core\Entity\Field\FieldDefinitionInterface

Nitpick: needs a description.

Wim Leers’s picture

The patch looks sane to me. But since I'm not deeply familiar with all things Entity & Field API, I cannot RTBC this.

effulgentsia’s picture

FileSize
892 bytes
25.67 KB

Addressed #2.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense and looks good !

YesCT’s picture

Issue tags: +RTBC July 1

This issue was RTBC and passing tests on July 1, the beginning of API freeze.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5207055 and pushed to 8.x. Thanks!

Berdir’s picture

Issue tags: -sprint

Untagging.

Status: Fixed » Closed (fixed)

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

effulgentsia’s picture

This doesn't fix all of core to do this

I grepped the rest of core for where there are typehints to Field, FieldInstance, FieldInterface, or FieldInstanceInterface that should be replaced with FieldDefinitionInterface, and only found one remaining function: #2058299: Fix content_translation_field_sync_widget() to act on FieldDefinitionInterface rather than $field, $instance.