Problem/Motivation

In #2521800: List key|label entry field is textarea, which doesn't give guidance towards the expected input, the form for options field settings was changed, and there is an outer form element with no #type:

    $element['allowed_values'] = [
      '#element_validate' => [[static::class, 'validateAllowedValues']],
      '#field_has_data' => $has_data,
      '#allowed_values' => $allowed_values,
      '#required' => TRUE,
      '#prefix' => '<div id="' . $wrapper_id . '">',
      '#suffix' => '</div>',
      '#access' => empty($allowed_values_function),
      'help_text' => ['#markup' => $this->allowedValuesDescription()],
    ];

This causes problems.

For example, a 3rd party module can't set #states on it, because the states system expects to find a #type on a form element.

Steps to reproduce

NA

Proposed resolution

Add type container

Remaining tasks

Review

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Issue fork drupal-3441061

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

joachim created an issue. See original summary.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Type container should probably work here right? May be a good novice task.

smustgrave’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative

Since it's been a few months just added it.

Doing this as part of my effort to lower my components queue.

smustgrave’s picture

Status: Active » Needs review

This simple?

joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

godotislate’s picture

Status: Reviewed & tested by the community » Needs review

Question on the MR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Applied suggestion, had to fix a typo but appears to still work.

godotislate’s picture

Status: Reviewed & tested by the community » Needs review

For MR comment.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Actually didn't know that. But applied.

godotislate’s picture

I did a manual test to compare the markup for this part of the form:

  1. Install standard
  2. Create a new content type
  3. Create a new Selection list field
  4. Choose Text and give field a label
  5. Inspect the "Allowed values" element in the browser

HEAD:

<div id="allowed-values-wrapper--Yib5OiwY0kc"><p>The name will be used in
  displayed options and edit forms.<br>The value is automatically generated
  machine name of the name provided and will be the stored value.</p>

  ...

MR 16154:

<div data-drupal-selector="allowed-values-wrapper-qcqzftj-hkw"
     id="allowed-values-wrapper--QCQzFtJ_hkw"
     class="js-form-wrapper form-wrapper"><p>The name will be used in displayed
  options and edit forms.<br>The value is automatically generated machine name
  of the name provided and will be the stored value.</p>

...

Structure is equivalent, and ID generation of the wrapper div is the same. Wrapper div has additional attributes from the container element, but that should be fine.

  • godotislate committed 8eacbb04 on 11.x
    fix: #3441061 ListItemBase::storageSettingsForm() 'allowed_values' form...

  • godotislate committed c19d29d2 on main
    fix: #3441061 ListItemBase::storageSettingsForm() 'allowed_values' form...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed c19d29d to main and 8eacbb0 to 11.x. Thanks!

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.

Status: Fixed » Closed (fixed)

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