Problem/Motivation

Most sites will need to update to PHP 8.1 soon-ish. This modules produces a deprecation error when running php 8.1

Steps to reproduce

Update to PHP 8.1 and visit status report or updates report page.

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() (line 358 of core/lib/Drupal/Component/Utility/UrlHelper.php).

Drupal\Component\Utility\UrlHelper::stripDangerousProtocols(NULL) (Line: 213)
Drupal\Component\Render\FormattableMarkup::placeholderFormat('Check this out from @sitename: :base_url:current_path', Array) (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
rawurlencode(Object) (Line: 58)
Drupal\Component\Utility\UrlHelper::buildQuery(Array) (Line: 534)
Drupal\Core\Url->toUriString() (Line: 51)
Drupal\mgv\Plugin\GlobalVariable\SocialSharingEmail->getValue() (Line: 78)
Drupal\mgv\MgvPluginManager->getNamespacedValue('social_sharing\email', Object) (Line: 64)
Drupal\mgv\MgvPluginManager->getVariables() (Line: 116)

Issue fork mgv-3300192

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

bserem created an issue. See original summary.

bserem’s picture

Status: Active » Needs review
bserem’s picture

Also takes care of this deprecation error too:

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('Check this out from @sitename: :base_url:current_path', Array) (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
rawurlencode(Object) (Line: 58)
Drupal\Component\Utility\UrlHelper::buildQuery(Array) (Line: 534)
Drupal\Core\Url->toUriString() (Line: 51)
Drupal\mgv\Plugin\GlobalVariable\SocialSharingEmail->getValue() (Line: 78)
Drupal\mgv\MgvPluginManager->getNamespacedValue('social_sharing\email', Object) (Line: 64)
Drupal\mgv\MgvPluginManager->getVariables() (Line: 116)
bserem’s picture

Status: Needs review » Needs work
bserem’s picture

So, the problem was elsewhere, I missed it at first but the problem comes from https://git.drupalcode.org/project/mgv/-/blob/2.1.x/src/Plugin/GlobalVar... which returns null.

bserem’s picture

Status: Needs work » Needs review
bserem’s picture

So, I'm digging deeper on this. None of the SocialSharingEmail, SocialSharingFaceboo, SocialSharingLinkedIn, SocialSharingTwitter work properly. regardless if their tests pass.
I am on PHP 8.1, haven't tested with anything else. In all the above 4 classes, the Url::fromUri doesn't get it's parameters populated from $this->getDependency

bserem’s picture

Status: Needs review » Needs work

So, these lines: https://git.drupalcode.org/project/mgv/-/blob/2.1.x/src/Plugin/GlobalVar...
always return an empty array and that's causing the problems.

kyberman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.7 KB

Hi, I found the problem was the plugin construction phase (plugin definition was not used).
The attached patch solves the error and fills the variables with correct values.
Could you please review it? Thank you.

Btw, tests don't look to be correct, so it would be great to fix them.

Status: Needs review » Needs work

The last submitted patch, 12: mgv-deprecated_function-3300192-12.patch, failed testing. View results

kyberman’s picture

StatusFileSize
new5.17 KB

Here is an attempt to fix tests.

kyberman’s picture

Status: Needs work » Needs review

And here we are - tests are fixed and passing. Could someone review it?

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

  • voleger committed 551fca2 on 2.2.x
    Issue #3300192 by kyberman, voleger: PHP 8.1 Deprecated function
    
voleger’s picture

Status: Needs review » Fixed

thanks, fixed

Status: Fixed » Closed (fixed)

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