Youtube enhancer plugin using deprecated function call

Created on 13 December 2023, about 1 year ago
Updated 13 September 2024, 3 months ago

Problem/Motivation

When enabling the oembed_lazyload_youtube submodule an error is thrown in php 8.1

Deprecated function: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\oembed_lazyload_youtube\Plugin\oembed_lazyload\ProviderEnhancer\YoutubeEnhancer->getEmbedCode() (line 75 of modules/contrib/oembed_lazyload/modules/oembed_lazyload_youtube/src/Plugin/oembed_lazyload/ProviderEnhancer/YoutubeEnhancer.php).

Steps to reproduce

Install module, enabled formatter on youtube video, navigate to page that includes an embedded youtube video using the formatter.

Proposed resolution

I propose changing line 75 in oembed_lazyload_youtube/src/Plugin/oembed_lazyload/ProviderEnhancer/YoutubeEnhancer.php) from

return preg_replace('/[?&#].*/', '', $embed_code);
to
return preg_replace('/[?&#].*/', '', $embed_code ?? ''); so that a NULL value use never passed to the preg_replace function. I'm not sure this is the best solution, but it seems like other functionality in Drupal core has been patched this way to remove errors.

Remaining tasks

I will provide a patch.

User interface changes

None.

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States boyerj

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024