These functions in name.module don't trim the values when testing for empty:
name_get_additional_component()
name_element_validate()
name_element_validate_is_empty()

CommentFileSizeAuthor
name_empty.patch1.24 KBpromes

Comments

PROMES created an issue. See original summary.

alan d.’s picture

Category: Bug report » Feature request

Note feature request rather than bug report as Drupal doesn't trim form values by default ;)

Does Trim work with the Name fields? (https://www.drupal.org/project/trim)

mohit.bansal623’s picture

Status: Active » Needs review

The creator already updated the patch and it is passed, do we need to add something in this need more information, trim() is a php function which will work in all cases.

alan d.’s picture

The functionality is non-standard Drupal which was the point I was making. I definitely didn't confuse the Trim module with the PHP trim() function if that was what you were implying! There is a core issue from a million years ago (cough 2006) that covers this in text fields but it still hasn't made it into core.

Do we make the module work in a sane but non-standard way?

promes’s picture

I didn't know this core issue. Thanks for your explanation.

alan d.’s picture

Status: Needs review » Needs work

Worthy feature if Trim module doesn't work. Either we should look at compatibility with that module or make this as a new feature :)

promes’s picture

I think a new feature is ok. Up till the core patch is ready. Afterwards switch.
But then I recommend also to trim the resulting components before storing them in function massageFormValues() in src\Plugin\Field\FieldWidget\NameWidget.php: just a simple loop before the return statement:

    foreach ($new_values as $key0 => $items) {
      foreach ($items as $key1 => $item) {
        $new_values[$key0][$key1] = trim($item);
      }
    }

Maybe there are more places...

bluegeek9’s picture

Status: Needs work » Closed (works as designed)

Drupal core does not trim field values. This can be done with others modules like Trim

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support of this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project, including:
  • Triaging issues and adding more context to existing issues.