Problem/Motivation

A deprecated warning is triggered when adding a content item with URL-Alias in the form. If there is no URL-Pattern for this content type you get a deprecated warning. ONLY ON PHP 8.5!

Steps to reproduce

  1. Fresh DDEV setup
  2. PHP Version 8.5
  3. Drupal Version ~11.3.0
  4. Edit a content type with URL-Alias in the form BUT without a pattern.

Proposed resolution

Investigate and fix the deprecated warning caused by using a null value as an array offset in `PathautoGenerator`. Ensure that all array keys used for cached pattern lookups are normalized before access.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork pathauto-3579655

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

gashunk created an issue. See original summary.

gashunk’s picture

Status: Needs work » Needs review
gashunk’s picture

Title: Depricated error when adding media item. » Deprecated error when adding media item.
mably’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce, +Needs tests

Can you give us a full reproducible scenario on a fresh Drupal instance please (Drupal version, PHP version, etc.)?

I haven't been able to reproduce the problem locally.

Could you eventually share the full stack trace of the warning you get?

gashunk’s picture

Status: Postponed (maintainer needs more info) » Needs review

Hey I can reproduce this using:
Fresh DDEV setup
PHP Version 8.5
Drupal Version ~11.3.0
Only installed Pathauto module

Edit a content type with URL-Alias in the form BUT without a pattern.

Full stack trace:

Deprecated function: Using null as an array offset is deprecated, use an empty string instead in Drupal\pathauto\PathautoGenerator->getPatternByEntity() (line 351 of /var/www/html/web/modules/contrib/pathauto/src/PathautoGenerator.php)

#0 /var/www/html/web/core/includes/bootstrap.inc(104): _drupal_error_handler_real()
#1 /var/www/html/web/modules/contrib/pathauto/src/PathautoGenerator.php(351): _drupal_error_handler()
#2 /var/www/html/web/modules/contrib/pathauto/src/PathautoWidget.php(80): Drupal\pathauto\PathautoGenerator->getPatternByEntity()
#3 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(464): Drupal\pathauto\PathautoWidget->formElement()
#4 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(222): Drupal\Core\Field\WidgetBase->formSingleElement()
#5 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(120): Drupal\Core\Field\WidgetBase->formMultipleElements()
#6 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(197): Drupal\Core\Field\WidgetBase->form()
#7 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(121): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm()
#8 /var/www/html/web/core/modules/node/src/Form/NodeForm.php(140): Drupal\Core\Entity\ContentEntityForm->form()
#9 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityForm.php(108): Drupal\node\Form\NodeForm->form()
#10 [internal function]: Drupal\Core\Entity\EntityForm->buildForm()
#11 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(554): call_user_func_array()
#12 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(303): Drupal\Core\Form\FormBuilder->retrieveForm()
#13 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#14 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#16 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(634): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}()
#17 [internal function]: Drupal\Core\Render\Renderer::{closure:Drupal\Core\Render\Renderer::executeInRenderContext():634}()
#18 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(635): Fiber->start()
#19 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#20 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#21 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(183): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}()
#22 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#24 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#25 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#26 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#27 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(118): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#28 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(92): Drupal\page_cache\StackMiddleware\PageCache->pass()
#29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#31 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(53): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#32 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(54): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#33 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(745): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#34 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#35 {main}

Hopes that helps!

vinodhini.e’s picture

Hi, Tested on Drupal 11.2.3 with PHP 8.3.21 using a fresh DDEV setup and installed Pathauto module.

Followed the steps:
Content → Media → Add a media item. The media uploaded successfully, and no deprecated warning appeared.

Could you clarify if any additional setup is needed to reproduce this issue? Thanks.

gashunk’s picture

Issue summary: View changes

I updated the description to further pin the issue.

gashunk’s picture

Title: Deprecated error when adding media item. » Deprecated error with PHP 8.5 on entity forms without pathauto patterns.
phoang’s picture

Patch works on 1.x-dev but not applies to 8.1.14
+1 RTBC

ewout goosmann’s picture

Hi,

I had the same issue on php8.5 and pathauto 8.1.14, so I created a patch.

joegraduate’s picture

Is this issue possibly a duplicate of #3576435: PHP 8.5 deprecation?

joegraduate’s picture

pasan.gamage’s picture

StatusFileSize
new1.55 KB

Updated patch to work with release 8.x-1.14 PHP 8.5

pasan.gamage’s picture

@joegraduate
Since #3576435 is already closed we may need to fix this here.

berdir’s picture

Status: Needs review » Postponed (maintainer needs more info)

This is almost certainly a duplicate. That was fixed recently and isn't released yet.

albert.garcia’s picture

I installed version 1.15 of the module (I think this is the one that @berdir is referring to), but this error keeps happening.

mably’s picture

Posted MR !173 as a sibling to !169 with a slightly different approach for the maintainers to choose from.

!169 fixes the symptom by coercing $entity->id() ?? 0 and $langcode ?: '', which makes the deprecation go away but caches every unsaved entity of a given type under the same [$entity_type_id][0] slot. !173 instead short-circuits at the top of getPatternByEntity() when $entity->isNew() and skips the per-id cache entirely for new entities — matching the intent that was already present in the existing if ($entity->isNew()) { return $pattern; } early return inside the loop. The language-override block is extracted into a small helper to avoid duplication between the two branches.

Both MRs make the PHP 8.5 deprecation go away; !173 removes it at the structural level rather than masking it with coercion, and avoids the shared-0-slot caching question for requests that build several unsaved entities of the same type (e.g. anywhere PathautoState::getValue() or PathautoWidget::formElement() is called).

Reviews welcome on either or both. Happy to fold ideas back into !169 or close !173 if !169 is preferred.

mably’s picture

Assigned: gashunk » Unassigned
Status: Postponed (maintainer needs more info) » Needs review
Issue tags: -Needs steps to reproduce, -Needs tests
mably’s picture

Assigned: Unassigned » berdir

I can confirm that I’ve successfully reproduced the issue and that MR 173 resolves it.

joegraduate’s picture

StatusFileSize
new3.74 KB

Attaching current MR !173 diff as patch usable with composer for 8.x-1.15.