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.
Comments
Comment #2
stephen-cox commentedHere's a patch
Comment #3
ekes commentedIt's making the assumption earlier too. Updated check for that line as well.
Comment #4
i-trokhanenkoComment #5
_tarik_ commented+1 to the 3265497-3.patch. It works fine for me, PHP - 8.1.18
Comment #6
mradcliffeI set #3358583: Warning: Trying to access array offset on value of type int in Drupal\domain_path_pathauto\DomainPathautoHelper->validateAlteredForm() as a duplicate because I think the current patch may address that as well.
Comment #7
bobburns commentedVersion 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
Comment #8
_tarik_ commentedHi, 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?
I almost sure that you got this error because erased a curly bracket somewhere in the file.
Comment #9
lendudeAs 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.
Comment #10
bbcPatch from #9 seems to be working well. Thanks!
Comment #12
wotts commentedPatch broke, re-rolled.
Comment #13
wotts commentedAnd this time with the correct file-name
Comment #16
quadrexdevThanks 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
Comment #17
i-trokhanenkoComment #19
i-trokhanenkoThanks!