As super user on a fresh Drupal installation go to:

/admin/structure/types/manage/article/fields/node.article.field_tags

Chose / type a new (non-existing) tag for the default value and press "Save".

Expected behaviour:
- a new tag with the given value is set as the default tag of the content type "Article"

Actual behavior:
- The following error message appears: Fatal error: Call to a member function uuid() on a non-object in /var/www/drupal-8/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceFieldItemList.php on line 74
- the default tag is not saved

Note: originally, the expected behavior wanted to save the default tag as well, but this is not a regression from Drupal 7 and is more a feature request.

(Found during the Drupal South 2014 Code Sprint in Wellington)

CommentFileSizeAuthor
#6 2195973-6.patch1 KBswentel

Comments

stefan lehmann’s picture

Issue summary: View changes
barraponto’s picture

Issue only happens when a new (non-existing) tag is chosen for the default value. Existing tags will work just fine.

stefan lehmann’s picture

Yep .. that's why I said fresh Drupal installation. There shouldn't be any tags yet.

barraponto’s picture

explicit is better than implicit ;)

larowlan’s picture

Issue tags: +Needs tests

NeedsTests

swentel’s picture

StatusFileSize
new1 KB

There's a larger problem at hand here. There's an error also on that page all the time:

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\FieldableDatabaseStorageController->loadMultiple() (line 147 of core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php).

Note: in Drupal 7, the default value widget does not save a tag. I would leave that as is, so that is not a regression. Saving it would be a (and also debatable) feature request.
However, it shouldn't blow up of course ;)

Attached patch fixes the error, but I'm not sure whether it's the right solution. We should probably look up further in the chain.

swentel’s picture

Status: Active » Needs review

Setting to needs review just for sure, but we surely need tests.

swentel’s picture

Issue summary: View changes
swentel’s picture

Issue summary: View changes
amateescu’s picture

swentel’s picture

@amateescu - did you click on save ? Because apparently in the other one it crashes still heavily ? :)

amateescu’s picture

Well, the fix there is just for the warning on the settings page..

revagomes’s picture

I came across this issue when I was working on #2193237: Warning because of empty value at array_flip().

I was thinking about the solution we have right now and I'm not sure about some points.

Taking in count that the system has to save the non existing term in order to store the default value I think the best thing to do would be warn the user about the creation of the default term with a description message on the field.

Earlier I was thinking to approach this with a checkbox to allow the user to decide if he/she wants to create the default value if it doesn't already exists. The thing is that now it's the default behavior of Drupal so maybe the best solution is to be verbose and let the user to know how the system works.

As @barraponto said:

explicit is better than implicit

I'm not sure if the creation of the default term outside the "admin/structure/taxonomy/manage/[vocabulary]/add" page makes sense for everyone but if that's the way the system works the end user has to be aware. OMHO

swentel’s picture

@amateescu: Ugh, right. Mine also still crashes if you fill in a non existing tag.
@revagomes: we need to keep the 'save a new one' as a feature request, it's not a regression.

swentel’s picture

Status: Needs review » Needs work

So this needs work too

stefan lehmann’s picture

Issue summary: View changes

Tried to make issue description more explicit, as suggested by barraponto.

stefan lehmann’s picture

Issue summary: View changes

Changed

"- a existing tag with the given value is set as the default tag of the content type "Article""

to

"- a new tag with the given value is set as the default tag of the content type "Article"

That's still the expected behavior or am I wrong? Otherwise the whole issue has a wrong description or there should be an issue with a refactoring guide, I suppose.

swentel’s picture

No, that's a feature request, it's not a regression compared to D7. We should fix the bug here first.

rodrigo panchiniak fernandes’s picture

I think the issue should be solved with an error message when the user tries to add a new tag as default tag. This would be the simplest way out. No term would be unexpectedly created, no feature request would be needed.

jhedstrom’s picture

Status: Needs work » Closed (duplicate)