Problem/Motivation

Another PHP 8 deprecation.

Steps to reproduce

Proposed resolution

Guard Link::prepareValue() against empty $values['uri'].

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

znerol created an issue. See original summary.

znerol’s picture

Status: Active » Needs review
FileSize
2.1 KB

Output of git diff -w (easier to read):

$ git diff --cached -w
diff --git a/src/Feeds/Target/Link.php b/src/Feeds/Target/Link.php
index f8bd3040..878f392b 100644
--- a/src/Feeds/Target/Link.php
+++ b/src/Feeds/Target/Link.php
@@ -29,6 +29,7 @@ class Link extends FieldTargetBase {
    * {@inheritdoc}
    */
   protected function prepareValue($delta, array &$values) {
+    if (!empty($values['uri'])) {
       $values['uri'] = trim($values['uri']);
 
       // Support linking to nothing.
@@ -36,7 +37,7 @@ class Link extends FieldTargetBase {
         $values['uri'] = 'route:' . $values['uri'];
       }
       // Detect a schemeless string, map to 'internal:' URI.
-    elseif (!empty($values['uri']) && parse_url($values['uri'], PHP_URL_SCHEME) === NULL) {
+      elseif (parse_url($values['uri'], PHP_URL_SCHEME) === NULL) {
         // @todo '<front>' is valid input for BC reasons, may be removed by
         //   https://www.drupal.org/node/2421941
         // - '<front>' -> '/'
@@ -50,5 +51,6 @@ class Link extends FieldTargetBase {
         }
       }
     }
+  }
 
 }
znerol’s picture

I can roll a patch with an early return if this is preferred. I.e.:

if (empty($values['uri'])) {
  return;
}
MegaChriz’s picture

Issue tags: +Needs tests

I think the approach in #3 is better.

It would also be good to have an automated test for this.

Does the link field get emptied when the passed value is null?

MegaChriz’s picture

It looks like that this issue is also being handled in #3306211: Deprecated function: trim(): Passing null is deprecated as of PHP 8.

znerol’s picture

#3306211: Deprecated function: trim(): Passing null is deprecated as of PHP 8 is indeed similar but it handles DateTargetBase. This issue is in Link target.

Do you like to merge those two issues?

Does the link field get emptied when the passed value is null?

What is supposed to happen if after prepareValue $values['uri'] is NULL?. Is that handled differently than if $values['uri'] is an empty string?

If the output should be the empty string if null is passed in, then we could fix it the same way as in #3306211: Deprecated function: trim(): Passing null is deprecated as of PHP 8, namely ($values['uri'] = trim((string) $values['uri']).

znerol’s picture

This patch implements idea from #3306211: Deprecated function: trim(): Passing null is deprecated as of PHP 8. No interdiff.txt, since this is a different approach than comment 2.

MegaChriz’s picture

Status: Needs review » Closed (duplicate)