Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junaidpv/4a8348846864b18d91bc40761afad37e to your computer and use it in GitHub Desktop.
Save junaidpv/4a8348846864b18d91bc40761afad37e 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 36be5e9..697c3ba 100644
--- a/src/Plugin/Field/FieldFormatter/ComputedStringFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/ComputedStringFormatter.php
@@ -57,9 +57,9 @@ 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