Problem/Motivation

Visiting the Manage Display page for a content type (/admin/structure/types/manage/[node]/display) causes a fatal error:

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given...

Steps to reproduce

  1. Enable Display Suite (ds) module.
  2. Go to /admin/structure/types/manage/[your_content_type]/display.
  3. If a field has no field template set or the formatter is not recognized, you encounter the error.
  4. The page crashes with a TypeError.

Proposed resolution

Replace:

$summary[] = 'Field template: ' . Html::escape($field_function);

With:

$summary[] = 'Field template: ' . Html::escape((string) $field_function);

This ensures no fatal error occurs when $field_function is NULL.

CommentFileSizeAuthor
#2 3522746-1.patch459 bytesandysipple

Comments

andysipple created an issue. See original summary.

andysipple’s picture

StatusFileSize
new459 bytes

See patch

  • swentel committed 81ad227d on 8.x-3.x
    Issue #3522746 by andysipple: TypeError: Drupal\Component\Utility\Html::...
swentel’s picture

Status: Active » Fixed

Interesting although I can't reproduce it at this point, but fair enough to fix it of course :)
I've changed it to use !empty() call instead of casting it to a string.

Thanks for the report!

Status: Fixed » Closed (fixed)

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