Hi!

My Drupal version is 9.3.7 and I'm using Login destination 8.x-2.0-beta1 with PHP 8.1 installed.

When /admin/config/people/login-destination/add is opened I receive warning:

Deprecated function: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in Drupal\login_destination\Form\LoginDestinationRuleForm->getUriAsDisplayableString() (line 266 of modules/contrib/login_destination/src/Form/LoginDestinationRuleForm.php).
Drupal\login_destination\Form\LoginDestinationRuleForm->getUriAsDisplayableString(NULL) (Line: 106)
Drupal\login_destination\Form\LoginDestinationRuleForm->form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm('login_destination_add_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Is there any patch to update parse_url() function?

CommentFileSizeAuthor
#16 3269290-16.patch543 bytesdarvanen
#4 3269290-4.patch606 bytesvictoria-marina

Comments

almador created an issue. See original summary.

almador’s picture

Issue tags: +PHP 8.1
victoria-marina’s picture

Assigned: Unassigned » victoria-marina

I'll work on this.

victoria-marina’s picture

Assigned: victoria-marina » Unassigned
Status: Active » Needs review
StatusFileSize
new606 bytes

I made a patch, hope it helps! Please, review it.

almador’s picture

thanks, Victoria-Marina!

one more error:

Deprecated function: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::escape() (line 424 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::escape(NULL) (Line: 262)
Drupal\Component\Render\FormattableMarkup::placeholderEscape(NULL) (Line: 208)
Drupal\Component\Render\FormattableMarkup::placeholderFormat('Weight for @title', Array) (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString() (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 50)
__TwigTemplate_930c8f1264878f11931bcb7ed5b9f11c->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('core/themes/seven/templates/classy/form/form-element-label.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('form_element_label', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 59)
__TwigTemplate_25ac74d1ecb5e0c29c444031eb551a2b->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('core/themes/seven/templates/classy/form/form-element.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('form_element', Array) (Line: 478)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 179)
__TwigTemplate_33ee205abbd5c84bc290da98f7be6b11->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('core/themes/seven/templates/classy/dataset/table.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('table', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
victoria-marina’s picture

@almador can you put here the steps to reproduce this error?

almador’s picture

@victoria-marina

1. install Login destination 8.x-2.0-beta1 on Drupal version is 9.7.3 with PHP 8.1
2. visit /admin/config/people/login-destination

victoria-marina’s picture

@almador Sorry, but the error isn't showing.

almador’s picture

@victoria-marina

Does your php is 8.1.3?

And what is your settings at /admin/config/development/logging ?

victoria-marina’s picture

@almador "All messages".

almador’s picture

@victoria-marina my settings is "All messages, with backtrace information", but I'm not sure that's the reason

almador’s picture

I've found Html::escape in src/Entity/LoginDestination.php

Tried to replace Html::escape($label); with Html::escape($label ?? '');, but it doesn't solved the issue.

victoria-marina’s picture

@almador Actually I don't think this is related to this module. Because on the error message, there isn't a path related to the module. On the first error, we got this path: modules/contrib/login_destination/src/Form/LoginDestinationRuleForm.php

almador’s picture

@victoria-marina, but this error appears only at /admin/config/people/login-destination

and as I said before "I've found Html::escape in src/Entity/LoginDestination.php"

p.s. Seems that this patch could solve the issue

https://www.drupal.org/files/issues/2022-03-06/escape-3268036.patch

It is from https://www.drupal.org/project/drupal/issues/3268036

If someone wants to add this patches, here is the part of my composer.json:

"extra": {
		"patches": {
			"drupal/login_destination": {
				"Resolve PHP 8.1 deprecation": "https://www.drupal.org/files/issues/2022-03-14/3269290-4.patch"
			},
			"drupal/core": {
				"htmlspecialchars fix": "https://www.drupal.org/files/issues/2022-03-06/escape-3268036.patch"
			}
		},
almador’s picture

Issue summary: View changes
darvanen’s picture

StatusFileSize
new543 bytes

Backtrace shows this is happening when building the form, it is definitely triggered by the module passing an empty string to getUriAsDisplayableString:

Deprecated function: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in Drupal\login_destination\Form\LoginDestinationRuleForm->getUriAsDisplayableString() (line 266 of modules/contrib/login_destination/src/Form/LoginDestinationRuleForm.php).
Drupal\login_destination\Form\LoginDestinationRuleForm->getUriAsDisplayableString(NULL) (Line: 106)
Drupal\login_destination\Form\LoginDestinationRuleForm->form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)

This is because when the form is empty $login_destination->getDestination() returns null.

The simplest and easiest to read fix is to abort all the checks if presented with an empty value. Patch attached.

  • rsvelko committed af7d10c on 8.x-2.x
    Issue #3269290 by victoria-marina, darvanen, almador: Deprecated...
rsvelko’s picture

Status: Needs review » Fixed

Thanks everyone! Patch applied, commited and pushed. The newest module release contains it.

Status: Fixed » Closed (fixed)

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