I got the error above if the field formatter settings contain an array as value. To fix that I added a condition which checks whether the value is an array. A use case is the Linked Field module - I couldn't change the wrapper of the ds title field without getting that error.

Comments

yannickoo’s picture

Status: Active » Needs review
StatusFileSize
new530 bytes
yannickoo’s picture

StatusFileSize
new568 bytes

Just guessing that we need the same for Drupal 8, attached patch.

swentel’s picture

Status: Needs review » Fixed

Looks sane, committed and pushed, thanks!

Status: Fixed » Closed (fixed)

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

inventlogic’s picture

I am getting this error when trying to add the physical fields weight or dimension to a display suite display mode.

I am using the 7.x-2.4 version of display suite which has this patch but it does not fix the issue for the physical fields.

The error occurs every time i change the region for the fields which immediately generates an Ajax error.

The error message I am seeing in the Firefox console

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/virtualsites/mysite/html/includes/bootstrap.inc on line 1559

Why does the patch not fix the issue for the physical fields?

a.milkovsky’s picture

Please fix it also in the 7.x-1.x branch...
ISSUE LINK: Warning: htmlspecialchars() ....

tontoman’s picture

Issue summary: View changes

I had the same problem and basically what fixed it for me was that I went through the Content types that we causing the problem and I discovered that I have dollar values on the content types with a decimal point and it needed to be a whole numbers .... so 0.5 and 1.2 was what was causing the problem in my case. Hope this helps someone. Peace.

kevinquillen’s picture

Version: 7.x-2.x-dev » 8.x-2.3
Status: Closed (fixed) » Needs review

Not sure if this belongs in the core queue or not, but I get this error with DS + Paragraphs enabled. Specifically related to a datetime field with the formatter set to 'Time ago'.

The options for future date and past date do not show on the field settings form. The settings summary for these values are being passed as arrays.

Warning: htmlspecialchars() expects parameter 1 to be string, array given in Drupal\Component\Utility\Html::escape() (line 407 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::escape(Array) (Line: 257)
Drupal\Component\Render\FormattableMarkup::placeholderEscape(Array) (Line: 229)
Drupal\Component\Render\FormattableMarkup::placeholderFormat('Future date: %display', Array) (Line: 209)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 20)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
implode('', Array) (Line: 561)
Drupal\Core\Template\TwigExtension->safeJoin(Object, Array, '') (Line: 44)
__TwigTemplate_f821c77039c217f90bf7a8f976486c27a1fbd3d077f048bd0be538f78a56fbe7->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 121)
Drupal\Core\Template\TwigEnvironment->renderInline('{{ summary|safe_join("") }}', Array) (Line: 57)
Drupal\Core\Render\Element\InlineTemplate::preRenderInlineTemplate(Array)
call_user_func(Array, Array) (Line: 384)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 467)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 183)
__TwigTemplate_98cf6ee9c325be56e5f6e2b50b209532e42534eaeb86ca76b1fbc0eee1a03602->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 46)
__TwigTemplate_39e23d604ed96fc8c3308b7f9a5ae10420721fc4f14f9274e17e981775352774->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/stable/templates/admin/field-ui-table.html.twig', Array) (Line: 389)
Drupal\Core\Theme\ThemeManager->render('field_ui_table', Array) (Line: 438)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 451)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 232)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 122)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 95)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 116)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 103)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 631)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Warning: htmlspecialchars() expects parameter 1 to be string, array given in Drupal\Component\Utility\Html::escape() (line 407 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::escape(Array) (Line: 257)
Drupal\Component\Render\FormattableMarkup::placeholderEscape(Array) (Line: 229)
Drupal\Component\Render\FormattableMarkup::placeholderFormat('Past date: %display', Array) (Line: 209)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 20)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
implode('', Array) (Line: 561)
Drupal\Core\Template\TwigExtension->safeJoin(Object, Array, '') (Line: 44)
__TwigTemplate_f821c77039c217f90bf7a8f976486c27a1fbd3d077f048bd0be538f78a56fbe7->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 121)
Drupal\Core\Template\TwigEnvironment->renderInline('{{ summary|safe_join("") }}', Array) (Line: 57)
Drupal\Core\Render\Element\InlineTemplate::preRenderInlineTemplate(Array)
call_user_func(Array, Array) (Line: 384)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 467)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 183)
__TwigTemplate_98cf6ee9c325be56e5f6e2b50b209532e42534eaeb86ca76b1fbc0eee1a03602->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 46)
__TwigTemplate_39e23d604ed96fc8c3308b7f9a5ae10420721fc4f14f9274e17e981775352774->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/stable/templates/admin/field-ui-table.html.twig', Array) (Line: 389)
Drupal\Core\Theme\ThemeManager->render('field_ui_table', Array) (Line: 438)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 451)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 232)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 122)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 95)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 116)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 103)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 631)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I noticed that the core Post date on a node type does not have a 'Time ago' format option, it only lets you select date formats (long, medium, short).

I would suspect this is possibly a core issue though I could not find a relevant issue for it, because without DS enabled, this error is never displayed for me on field UI display forms.

The last submitted patch, 1: ds-htmlspecialchars-1982646-1.patch, failed testing.

The last submitted patch, 1: ds-htmlspecialchars-1982646-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: ds-htmlspecialchars-1982646-2.patch, failed testing.

The last submitted patch, 1: ds-htmlspecialchars-1982646-1.patch, failed testing.

The last submitted patch, 2: ds-htmlspecialchars-1982646-2.patch, failed testing.

The last submitted patch, 2: ds-htmlspecialchars-1982646-2.patch, failed testing.

kevinquillen’s picture

Sorry - didn't mean to select 'Needs Review' and blow up testbot.

sgurlt’s picture

I can confirm what kevinquillen wrote, I get the same with paragraphs.

aspilicious’s picture

Well this is a core issue

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    $future_date = new DrupalDateTime('1 year 1 month 1 week 1 day 1 hour 1 minute');
    $past_date = new DrupalDateTime('-1 year -1 month -1 week -1 day -1 hour -1 minute');
    $summary[] = t('Future date: %display', array('%display' => $this->formatDate($future_date)));
    $summary[] = t('Past date: %display', array('%display' => $this->formatDate($past_date)));

    return $summary;
  }
$this->formatDate($future_date) 

Returns an array with cachable metadata in stead of a string breaking the summary

aspilicious’s picture

Status: Needs work » Closed (duplicate)
slanger’s picture

StatusFileSize
new1.31 KB

I agree with @aspilicious: The field formatter for "Time ago" in core is trying to replace a string token with an array of data, resulting in the error.

The following patch solved the problem for me. It renders the array of data into a string.

Thanks for tracking down the problem, @aspilicious!