Problem/Motivation

The following errors are thrown when a node is saved when Domain Path Pathauto is enabled but there are no pathauto patterns for the content type.

    Warning: Undefined array key "pathauto" in Drupal\domain_path_pathauto\DomainPathautoHelper->validateAlteredForm() (line 159 of modules/contrib/domain_path/modules/domain_path_pathauto/src/DomainPathautoHelper.php).
    Warning: Undefined array key "pathauto" in Drupal\domain_path_pathauto\DomainPathautoHelper->validateAlteredForm() (line 159 of modules/contrib/domain_path/modules/domain_path_pathauto/src/DomainPathautoHelper.php).
    Warning: Undefined array key "pathauto" in Drupal\domain_path_pathauto\DomainPathautoHelper->submitAlteredEntityForm() (line 226 of modules/contrib/domain_path/modules/domain_path_pathauto/src/DomainPathautoHelper.php).
    Warning: Undefined array key "pathauto" in Drupal\domain_path_pathauto\DomainPathautoHelper->submitAlteredEntityForm() (line 226 of modules/contrib/domain_path/modules/domain_path_pathauto/src/DomainPathautoHelper.php).

There have been a number of similar issues fixed, but there are still places in the code there array access is attempted, but there is no check to ensure the key exists.

Steps to reproduce

  • Enable Domain Path Pathauto and all dependencies.
  • Ensure there isn't a Pathuto pattern for a content type.
  • Create a new node of that content type.
  • See the warnings in the logs.

Proposed resolution

Check the array keys exist before trying to access them.

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:

Comments

stephen-cox created an issue. See original summary.

stephen-cox’s picture

Here's a patch

ekes’s picture

StatusFileSize
new2.07 KB
new633 bytes

It's making the assumption earlier too. Updated check for that line as well.

i-trokhanenko’s picture

Status: Active » Needs review
_tarik_’s picture

+1 to the 3265497-3.patch. It works fine for me, PHP - 8.1.18

mradcliffe’s picture

bobburns’s picture

Version 1.3 takes down the site

I authored the change in https://www.drupal.org/project/domain_path/issues/3358583 and I had previously tried the isset fix on line 163, which did not work. I admit I did not do the DomainPathHelper.php fix of patch 3 here.

I had used

if (!isset($domain_path_data['pathauto']) && !$domain_path_data['pathauto']) {

which did not work

So . . .I changed line 163

from
if (!$domain_path_data['pathauto']) {

to
if (is_array(!$domain_path_data) ? $domain_path_data['pathauto'] : NULL) {

the error has not shown again when saving products

Now version 1.3 throws this instead

The website encountered an unexpected error. Please try again later.
ParseError: syntax error, unexpected token "public" in Composer\Autoload\{closure}() (line 209 of modules/domain_path/modules/domain_path_pathauto/src/DomainPathautoHelper.php).

WHICH TAKES DOWN THE SITE

so, I went back to version 1.2 and marked it as 1.3 which does not throw this error to keep calm and carry on

_tarik_’s picture

Hi, bobburns
I checked the problem that you described in the issue. And it looks like this patch should fix it.
Could you provide more details about how you tried to apply the patch?

The website encountered an unexpected error. Please try again later.
ParseError: syntax error, unexpected token "public" in Composer\Autoload\{closure}() (line 209 of modules/domain_path/modules/domain_path_pathauto/src/DomainPathautoHelper.php).

I almost sure that you got this error because erased a curly bracket somewhere in the file.

lendude’s picture

StatusFileSize
new880 bytes
new2.06 KB

As far as I can tell the modification to the check here in DomainPathautoHelper is wrong and the check from #3358583: Warning: Trying to access array offset on value of type int in Drupal\domain_path_pathauto\DomainPathautoHelper->validateAlteredForm() is correct, we only want to run validation if $domain_path_data['pathauto'] is set (so pathauto is enabled for this content type) but is not true, which is what the comment point to when we should be validating.

The other modification here look good.

bbc’s picture

Patch from #9 seems to be working well. Thanks!

wotts made their first commit to this issue’s fork.

wotts’s picture

StatusFileSize
new2.05 KB

Patch broke, re-rolled.

wotts’s picture

StatusFileSize
new2.05 KB

And this time with the correct file-name

quadrexdev made their first commit to this issue’s fork.

quadrexdev’s picture

Status: Needs review » Reviewed & tested by the community

Thanks everyone for putting some effort here. I have created a merge request with changes from the attached patches.

We have some failing jobs and appropriate issues to resolve:

1. Drupal 11 compatibility (PHPUnit) - https://www.drupal.org/project/domain_path/issues/3429923
2. Validation jobs (PHPUnit, phpcs, eslint) - https://www.drupal.org/project/domain_path/issues/3409106

Those two should be resolved first

i-trokhanenko’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

i-trokhanenko’s picture

Status: Patch (to be ported) » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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