Problem/Motivation

When using the field widget, the only available field type is a select field. We wish to also allow select2 as a select type.

Steps to reproduce

None.

Proposed resolution

Allow to select a different select type and allow select2 when the module is available.

Remaining tasks

  • Review patch

User interface changes

The webmaster is able to set the select type for the field widget.

API changes

None.

Data model changes

New schema for the select type for the field widget.

Issue fork yearonly-3226711

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tim-diels created an issue. See original summary.

tim-diels’s picture

Status: Active » Needs review
StatusFileSize
new2.63 KB
gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned

Patch #2 not working in drupal 9.4.8.Please reroll the patch.
Thank you.

justcaldwell’s picture

Version: 9.0.0 » 9.0.x-dev
tim-diels’s picture

Re-rolled patch.

mortona2k made their first commit to this issue’s fork.

mortona2k’s picture

Version: 9.0.x-dev » 9.x-dev

Changing target branch.

justcaldwell’s picture

I'm inclined to keep the widget code as simple as possible.

For projects that need this, wouldn't it be possible to add support for yearonly field items to the select2 widget itself by implementing hook_field_widget_info_alter()? Something like:

function mymodule_field_widget_info_alter(array &$info) {
  if (isset($info['select2'])) {
    $info['select2']['field_types'][] = 'yearonly';
  }
}
justcaldwell’s picture

Status: Needs review » Closed (won't fix)

I confirmed that you can use the method in #10 to enable the select2 widget for yearonly fields. That said, I get the error below when trying to add new content after switching to the select2 widget.

Error: Call to a member function getSettableOptions() on null in Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions()

That's in my Drupal 10.4.9 test instance. YMMV.

Absent other evidence, I'll chalk that up to the fact that Select2 is no longer actively maintained, and is replaced by Tagify.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.