Hi,

Problem/Motivation

Like many people (#1597988: Simplify reusing forms between widget's and elements) when I am building a custom form I would like to use a form element that is actually just a field widget: Image or Link fields for instance.

For example if we want to add a link element to a custom form, we have to redevelop what the Link widget already do (it creates duplicated code, maybe some security issues etc..).

Proposed resolution

A good thing could be to take example of what the Address module do.
It defined a form element address and use it on the widget.

So rather than to "hardcode" the "form element" in the widget, it could be interesting to define a real form element. Thanks to that we have reusable code.

It could be a good practice to follow for contrib module.

Remaining tasks

  • Defined which fields needs to expose a form element
  • Create a patch

User interface changes

None

API changes

None.

Data model changes

None.

If you find this interesting, I'll be glad to work on it with some help.

Comments

beram created an issue. See original summary.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

beram’s picture

A sandbox module has been started for the moment: https://www.drupal.org/sandbox/beram/2915340

It starts with a quick implementation of a link form element as I needed it.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.