Normally, when a Drupal field is set to "Unlimited" (on the Field Settings screen), one has to click the "Add another item" button to generate an additional instance of it. However, with the Name field, an extra instance is erroneously tacked on each time the field is saved -- a problem that gets compounded with each additional update.

For example: if you added the Name field to a content type, set "Allowed number of values" to "Unlimited," then saved a node seven times (leaving the Name field blank each time), eight instances of the Name field would end up being attached to that node.

Interestingly, this same phenomenon happens when just configuring the Name field. On the Edit screen, in the "Default Value" section, an additional instance of the Name field is added every time that screen is saved.

These extra instances of the field become problematic when the Name field data is being displayed. If you added two names to a Name field and then viewed the node, the data would be formated like there are actually three or more names.

It's almost like the "blank" instance of the Name field isn't actually empty -- at least, as far as Drupal is concerned -- causing an extra instance of the field to be erroneously generated each time.

Comments

slanger created an issue. See original summary.

slanger’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new3.78 KB

The following patch should fix the problem. I'm sure there's a more elegant solution out there; but until someone figures it out, this will hopefully do the trick. :-)

When "Allowed number of values" is set to "Unlimited" on a patched version of the name field, it should behave more like other Drupal fields with that setting.

  • On the field Edit screen: Even if you click "Add another item" several times in the the "Default value" section and save it, returning to that screen should always show no more than two instances of the field.
  • As part of a content type (or the like): If you leave the field blank and save the node, You'll find no additional instances of the name field when you edit it later on. If you enter a name and save it, an extra blank instance will appear below it the next time you edit it, which is typical behavior in Drupal.

Testing

I tested to see if this patch has any negative effects when allowed number of values is set to a specific number.

  • Limited to 1: Behaved just as before.
  • Limited to 5: Behaved just as before. All 5 instances are shown at once, with no ability to add or subtract them.
slanger’s picture

StatusFileSize
new3.76 KB

Tweaked the patch and queued it to be tested.

alan d.’s picture

Status: Patch (to be ported) » Needs review

if applicable, set to Patch (to be ported) after it is committed to 8.x :)

slanger’s picture

Status: Needs review » Patch (to be ported)

@Alan D.: Let me know if there's something else you need me to do besides just changing the status. :-)

alan d.’s picture

Status: Patch (to be ported) » Needs review
Issue tags: +Needs backport to D7

So patch is for D8 and has not been reviewed by anyone (coding standards and if it actually works). So the correct status is "Needs Review"

Once RTBTC, it would be applied to 8.x.

At this point, it is either fixed OR set to backport to 7.x IFF 7.x needs it

So, as of right now I haven't reviewed and a second person should do this before changing the status to Reviewed & tested by the community. I added the tag "needs backport to D7" just in case.

alan d.’s picture

Appears that massageFormValues() handles this nicely :)

alan d.’s picture

Title: Allowed number of values = Unlimited » Saving empty name fields
Status: Needs review » Fixed
alan d.’s picture

  • Alan D. committed 6b815b8 on 8.x-1.x
    Issue #2849973 by slanger, Alan D.: Saving empty name fields
    

Status: Fixed » Closed (fixed)

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