Problem/Motivation

If I set taxonomy.settings override_selector to true, creation of terms fail in PHP 8.0.

TypeError : array_values(): Argument #1 ($array) must be of type array, null given dans array_values() (/opt/drupal/web/core/modules/taxonomy/src/TermForm.php ligne 120)

TypeError : count(): Argument #1 ($value) must be of type Countable|array, null given dans count() (/opt/drupal/web/core/modules/taxonomy/src/TermForm.php ligne 173)

Steps to reproduce

drush cset taxonomy.settings override_selector 1

I need to set this configuration to true because I have a vocabulary with a huge amount of terms (> 500 000) without tree structure.
If I let this config to false, this leads to memory allocation fatal error in term form.

But when, this config is set to true, the creation of term fails because $form_state->getValue('parent') returns null and in PHP 8.0 array_values and count don't allow null argument (warning in PHP 7.4).

Proposed resolution

See patch

Issue fork drupal-3242538

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mounir_abid created an issue. See original summary.

cilefen’s picture

Issue tags: -taxonomy terms, -taxonomy.settings override_selector

The default value of this setting is false. How could automated tests not be failing on this?

mounir_abid’s picture

Issue summary: View changes
mounir_abid’s picture

Issue summary: View changes
mounir_abid’s picture

Sorry, I was wrong, it's the opposite.
you must pass the configuration to true.

cilefen’s picture

Issue tags: +Bug Smash Initiative

What do you mean by that?

mounir_abid’s picture

To reproduce the issue, you have to set
taxonomy.settings override_selector to true.

cilefen’s picture

Status: Active » Needs work
Issue tags: +Needs tests

If this is a broken feature then it is possible to add an automated test that will demonstrate the bug.

danflanagan8’s picture

Title: Term creation fail with php 8 » Term creation fail with php 8 when override_selector = TRUE

This is a duplicate of #3090877: Warnings on terms creating when override_selector = TRUE. This IS is much clearer though (for example, the summary exists!), so I think I'm going to close that one. I'm updating the issue title here too.

danflanagan8’s picture

Here's a lil test to expose the bug.

There are some other issues related to override_selector that will naturally be able to add to this test. For example, #2985762: Terms created when override_selector = TRUE don't appear on Terms List/Overview page. First things first, though.

danflanagan8’s picture

The patch from @super_romeo on the duplicate issue looks good to me: https://www.drupal.org/files/issues/2019-10-30/3090877-3.drupal.Warnings...

I'm going to test that patch against the new fail test here. The interdiff I'm posting here is identical to @super_romeo's patch.

That patch also appears to solve a related issue #2985762: Terms created when override_selector = TRUE don't appear on Terms List/Overview page. So I've updated the fail test to include a test for that issue. And I'm going to close that as a duplicate.

So we definitely need to give credit for @super_romeo and @DigitalFrontiersMedia, who each put patches up for the issues I've closed.

danflanagan8’s picture

Version: 9.2.x-dev » 9.3.x-dev
danflanagan8’s picture

Ugh, first problem with branch then problem with cspell. I should mark all my test as FAIL. Let's try again and ignore the previous one...

The last submitted patch, 13: 3242538-13-FAIL.patch, failed testing. View results

DigitalFrontiersMedia’s picture

So we definitely need to give credit for @super_romeo and @DigitalFrontiersMedia, who each put patches up for the issues I've closed.

@danflanagan8 Very much appreciated! After 3 years, I figured I was the only one with that issue. :-D

danflanagan8’s picture

Hey @DigitalFrontiersMedia!

It's possible your issue is technically outdated rather than being a duplicate because I couldn't reproduce it. But your fix was essentially identical to this one. Whatever the case may be, I've added test coverage for your issue here and it passes.

larowlan’s picture

Credits

larowlan’s picture

Fixing credits, sorry for the noise

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Tested this out and confirmed the issue on PHP 8.1

With the patch I was able to create terms again.

See the tests-only patch failed too so looks good.

The last submitted patch, 13: 3242538-13-FAIL.patch, failed testing. View results

catch’s picture

Kicked off a 10.1.x test run since the last successful one here was against 9.3.x.

  • alexpott committed 86c4193 on 10.1.x
    Issue #3242538 by danflanagan8, mounir_abid, cilefen,...

  • alexpott committed f47fff7 on 10.0.x
    Issue #3242538 by danflanagan8, mounir_abid, cilefen,...

  • alexpott committed 5590462 on 9.5.x
    Issue #3242538 by danflanagan8, mounir_abid, cilefen,...

  • alexpott committed a243c34 on 9.4.x
    Issue #3242538 by danflanagan8, mounir_abid, cilefen,...
alexpott’s picture

Version: 9.5.x-dev » 9.4.x-dev
Status: Reviewed & tested by the community » Fixed

I committed this on 1st august but forgot to mark as fixed :)

Status: Fixed » Closed (fixed)

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