Problem/Motivation
Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\taxonomy\TermForm->buildEntity()
Steps to reproduce
1. Add a field that uses ajax in its widget to a vocabulary (for example file/image or a field with unlimited cardinality)
2. Go to the add term form
3. Trigger an ajax operation without entering a term name
Proposed resolution
Change \Drupal\taxonomy\Entity\Term::getName to conform to the interface and always return a string.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|
Issue fork drupal-3277238
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
Comment #2
BerdirComment #3
andregp CreditAttribution: andregp at CI&T commentedHere is a patch :)
Comment #4
hmendes CreditAttribution: hmendes at CI&T commentedTested the patch here and it worked for me, and the code follows the "Proposed resolution".
Steps:
Changing this to RTBC.
Comment #7
BerdirLooks like a random fail.
Comment #9
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedRetested patch #3 on Drupal 9.5.x. It's green so back to RTBC as per comment #4 and #7.
Comment #10
alexpottGiven we obviously have no test coverage of this I feel it is worth adding some.
We should be able to use \Drupal\Tests\taxonomy\Functional\TaxonomyImageTest as the basis for a test - we could make it a FunctionalJavascript test and go from there.
Comment #11
joachim CreditAttribution: joachim at Factorial GmbH commentedThat test got removed in #3305410: remove TaxonomyImageTest -- someone working on this will need to retrieve the test class from git history (removal commit is 0cf5ca1 on 10.1.x).
Comment #14
plopescNew patch including tests.
Instead of replicating the scenario in a new FunctionJavascript test, it makes the form validation less restrictive to make the bug visible.
Comment #16
smustgrave CreditAttribution: smustgrave at Mobomo commentedConfirmed the issue described and the patch #14 solves it.
And the failing test shows the issue is being solved.
Comment #18
Ajeet Tiwari CreditAttribution: Ajeet Tiwari at OpenSense Labs for DrupalFit commentedPlease review.
Comment #19
smustgrave CreditAttribution: smustgrave at Mobomo commentedRemoving credit for #18
As there was no interdiff
No explanation of change
And reroll removed most of the changes.
Failure in #14 seems random. Retesting but going to mark too.
Comment #20
lauriiiI don't think allowing to save an invalid term is best way to test this because it's certainly not a behavior we want to have to support.
Comment #21
BerdirI'm unsure, I agree it's somewhat uncommon, but that's already a fairly common scenario that we do "support", the way it works is that you then generate a node title/term name based on some other fields, for example with https://www.drupal.org/project/auto_entitylabel. Typically you hide the field then though (and can do that with nodes through the UI) but that's a minor difference. The same would indeed also happen there.
Comment #22
lauriiiIf the module wanted to ensure that the entity is only saved if it's valid, it should generate the title before saving it. Looks like it's currently done in
hook_entity_insert()
which means it's done after it has been saved. 🤷♂️Comment #23
lauriiiHere's a test that uses the steps from the issue summary.
Comment #25
Berdirloading the term by name to display it's name is a bit unecessary. imho it's sufficient to just check the success message based on $edit directly, we don't need to check that the term really exists?
Comment #26
lauriiiAddressed #25 👍
Comment #27
lauriiiNow that I'm looking at this again, it looks like
\Drupal\taxonomy\TermInterface::getName
is supposed to always returnstring
but\Drupal\Core\Entity\EntityInterface::label
might returnstring|\Drupal\Core\StringTranslation\TranslatableMarkup|null
. I think the right fix would be for\Drupal\taxonomy\Entity\Term::getName
to return empty string when\Drupal\Core\Entity\ContentEntityBase::label
returnsnull
.Comment #28
smustgrave CreditAttribution: smustgrave at Mobomo commentedMakes sense to me and can see the test-only patch fail in 23.
Ran locally too
Exception : Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated
Drupal\taxonomy\TermForm->buildEntity()() (Line: 152)
Comment #29
quietone CreditAttribution: quietone at PreviousNext commentedThe issue summary is clear and there is a proposed resolution. I read the comments and all questions have been answered. However, I notice that the last comment has changed the solution making the proposed resolution incorrect. And the title isn't quite right any more.
I looked at the patch and noticed a doc block missing, the use statements were not sorted, $module should have an @inheritdoc. I have made a patch for those.
I have updated the proposed resolution and tried for an better title.
Comment #31
Bhanu951 CreditAttribution: Bhanu951 as a volunteer commentedGot hit by this issue on 9.5.x . But patch from #29 did not fix it.
Seems Patch from #29 has random failure, rerunning the tests.
Comment #32
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems changes in #29 are good/all green
@Bhanu951 can you post the error/steps you're taking to get this issue?
Comment #34
quietone CreditAttribution: quietone at PreviousNext commentedRetesting.
Comment #36
lauriiiMoved #29 into MR. Looks like the CI is passing so moving back to RTBC.
Comment #37
xjm@lauriii Please remember to hide patch files from the IS when opening an MR. Thanks!
Comment #38
xjmI queued the test-only job. Results:
That is not the failure I expected.
Comment #39
xjmhttps://www.drupal.org/pift-ci-job/2723504 documents the expected test-only result, so the issue with the test-only job is not blocking. I reached out to the DA and committer team about it.
Comment #41
xjmI fixed a few nitpicks. Apparently the weird failure from the test-only job might be due to the MR not being rebased, so also fixed that. (Adding credit for @fjgarlin for identifying that issue.)
Meanwhile, saving issue credits.
Comment #42
xjmThe rebase did yield the correct test-only result:
Comment #46
xjmI could not think of any way that no longer returning an invalid
NULL
from this would be particularly disruptive, so I committed this to 11.x, 10.2.x, and 10.1.x. Thanks!Comment #47
xjm