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
| Issue category | Task because nothing is broken |
|---|---|
| Issue priority | Not critical because there is an easy workaround |
| Disruption | No disruption |
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | UriItem_default_wiget-2541412-1.patch | 529 bytes | john cook |
Comments
Comment #1
john cook commentedAdded default_wiget as suggested.
Comment #2
tstoecklerAwesome, 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.
Comment #3
alexpottSure 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!