Problem/Motivation

UriItem does not declare a default_widget so it cannot be used in an entity form unless the widget is specified explicitly.

// This should suffice and it does for other field types.
// The default widget is picked automatically.
BaseFieldDefinition::create('uri')
  ->setDisplayOptions('form', ['weight' => 0]);

// In fact, the following is needed, though.
BaseFieldDefinition::create('uri')
  ->setDisplayOptions('form', [
    'type' => 'uri',
    'weight' => 0,
]);

Proposed resolution

Because we already have a UriWidget the solution is trivial: Add a default_widget declaration to the UriItem annotation.

Specifically, find core\lib\Drupal\Core\Field\Plugin\Field\FieldType\UriItem.php and add a line of the form default_widget = "uri" to the annotation (the @FieldType stuff at the top of the file).

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because nothing is broken
Issue priority Not critical because there is an easy workaround
Disruption No disruption
CommentFileSizeAuthor
#1 UriItem_default_wiget-2541412-1.patch529 bytesjohn cook

Comments

john cook’s picture

Status: Active » Needs review
StatusFileSize
new529 bytes

Added default_wiget as suggested.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, works perfectly.

I don't think this needs tests because we don't actually use it in core, it's just a nice DX improvement. And we already have an issue (which I can't find right now) to generically test that all field items have a valid default widget and formatter, so that we won't be able to break this in te future.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Sure this makes sense and tests are not needed. This is beta permitted because it has 0 disruption and just makes sense. Committed be455a9 and pushed to 8.0.x. Thanks!

  • alexpott committed be455a9 on 8.0.x
    Issue #2541412 by John Cook: UriItem should have UriWidget as...

Status: Fixed » Closed (fixed)

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