Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junaidpv/898cb6f6e1fc0a3c02153bd04b212bef to your computer and use it in GitHub Desktop.
Save junaidpv/898cb6f6e1fc0a3c02153bd04b212bef to your computer and use it in GitHub Desktop.
To fix this warning message originated from the computed_field module: 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).
diff --git a/src/Plugin/Field/FieldFormatter/ComputedStringFormatter.php b/src/Plugin/Field/FieldFormatter/ComputedStringFormatter.php
index 583c34e..b160b07 100644
--- a/src/Plugin/Field/FieldFormatter/ComputedStringFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/ComputedStringFormatter.php
@@ -60,10 +60,10 @@ class ComputedStringFormatter extends ComputedFormatterBase {
protected function prepareValue($value) {
if ($this->getSetting('sanitized')) {
- return nl2br(Html::escape($value));
+ return !empty($value) ? nl2br(Html::escape($value)) : $value;
}
else {
- return nl2br($value);
+ return !empty($value) ? nl2br($value) : $value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment