Problem/Motivation

Currently, when a term reference field is not set to auto create new terms, its not possible to add terms without overwriting existing ones. I think this behavior should only be dependent on cardinality. Also it seems that the implemented autocomplete field does not even support auto creating terms (as documented here https://www.drupal.org/node/2418529).

Proposed resolution

If cardinality is 1 overwrite existing term, otherwise merge with existing terms.
Add support for term auto creation.

Remaining tasks

User interface changes

API changes

None

Data model changes

None

Comments

criz created an issue. See original summary.

criz’s picture

Status: Active » Needs review
StatusFileSize
new3.04 KB

Here is a patch.

Please note that when the maximum of allowed values (cardinality) is already populated for a node, an existing value will be overwritten, no matter if cardinality is not 1. This was also the case before this patch. Not sure how to handle this, as the description of the form field is not always true. Maybe at least a note in the readme would be good.

fjgarlin’s picture

Status: Needs review » Needs work
StatusFileSize
new17 KB

This line will add the new terms to the first available vocabulary, not the one selected:
'bundle' => array_values($target_bundles)[0],

Selected one: Test image

So in this example, new tags will be added to "Tags", but should be added to "Test"

fjgarlin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.39 KB

I altered slightly your patch to deal with the situation described above. Please test it out and let me know if it still does everything as you would expect. I tried myself and it was working but it'd be great a second pair of eyes.

criz’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Yes, I missed this setting. Tested and works.

  • fjgarlin committed cb25180 on 8.x-1.x authored by criz
    Issue #3248763 by fjgarlin, criz: Allow adding terms also for fields...
fjgarlin’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for this addition. I've pushed the change so I'll close the issue.

fjgarlin’s picture

Status: Fixed » Closed (fixed)