Problem/Motivation

We are trying to intergrate select2 but with the empty value (usually in drupal it's represented with _none) the title field is not showing up as a selectable option using https://www.drupal.org/project/select2_all

Steps to reproduce

  1. Enable select2_all and name modules.
  2. Add a name field with title options
  3. View the form to see the missing options

Proposed resolution

Instead of using empty string use the _none

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#10 name_none_placeholder-3384140-10.patch682 bytestkiehne

Issue fork name-3384140

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

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
joelpittet’s picture

We found out that my MR/patch stored the _none value which was not intended though I would have thought the nice tests here would catch that, nevertheless I updated it to strip it out similar to:
core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php:110

But considering NameWidget doesn't extend from that (and doesn't need to) I just grabbed the part that was needed.

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

  • heddn committed 7a74376b on 8.x-1.x authored by joelpittet
    Issue #3384140 by joelpittet, heddn: Empty value using _none instead of...
heddn’s picture

Status: Needs review » Fixed

Thanks for your contributions.

tkiehne’s picture

I'd hate to burst y'alls bubble here, but the filtering in the NameWidget uses array_search() which only returns the first key:

If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys() with the optional filter_value parameter instead.

https://www.php.net/manual/en/function.array-search.php

So, if we have both title and generational in the form and the user leaves both blank, only one of these is going to get massaged to remove the "_none".

Should be something like this instead:

      $indexes = array_keys($item, '_none', TRUE);
      foreach ($indexes as $index) {
        $item[$index] = '';
      }
derekw’s picture

I confirm -- I am seeing the behavior described in #8 and a blank "Generational" field is being rendered as _none by the default name formatter.

tkiehne’s picture

StatusFileSize
new682 bytes

I had to work up a patch to deploy a site tonight - here it is if it helps while waiting for a new release

heddn’s picture

@tkiehne can you post a new issue with that in it and link it here? I'd like to get this fixed pretty quickly.

tkiehne’s picture

#3491471 created

Status: Fixed » Closed (fixed)

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