Not sure who's issue this should be logged under so if it is the wrong place please tell me so i can create an issue with the other module.

I enabled custom_search module and as soon as I placed it in any of my regions I got the following error and the page never finished rendering.

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\Component\Render\HtmlEscapedText::render() in bootstrap_barrio_preprocess_form_element() (line 284 of themes/bootstrap_barrio/bootstrap_barrio.theme).

bootstrap_barrio_preprocess_form_element(Array, 'form_element', Array)
Drupal\Core\Theme\ThemeManager->render('form_element', Array)
Drupal\Core\Render\Renderer->doRender(Array)
Drupal\Core\Render\Renderer->doRender(Array, )
Drupal\Core\Render\Renderer->render(Array)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1)
__TwigTemplate_4c69e5991f3e160b935047dfe4777706db635ab67265fa6f4ec5c39794e17709->block_content(Array, Array)
Twig_Template->displayBlock('content', Array, Array)
__TwigTemplate_4c69e5991f3e160b935047dfe4777706db635ab67265fa6f4ec5c39794e17709->doDisplay(Array, Array)
Twig_Template->displayWithErrorHandling(Array, Array)
Twig_Template->display(Array)
Twig_Template->render(Array)
twig_render_template('themes/bootstrap_barrio/templates/block/block.html.twig', Array)
Drupal\Core\Theme\ThemeManager->render('block', Array)
Drupal\Core\Render\Renderer->doRender(Array)
Drupal\Core\Render\Renderer->doRender(Array, )
Drupal\Core\Render\Renderer->render(Array)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1)
__TwigTemplate_4eda0ce75fcd4d7c7bfea8acfbaae4f24ee45e1495f6c6cfc1fc2dfc1d49ff2b->block_head(Array, Array)
Twig_Template->displayBlock('head', Array, Array)
__TwigTemplate_4eda0ce75fcd4d7c7bfea8acfbaae4f24ee45e1495f6c6cfc1fc2dfc1d49ff2b->doDisplay(Array, Array)
Twig_Template->displayWithErrorHandling(Array, Array)
Twig_Template->display(Array)
Twig_Template->render(Array)
twig_render_template('themes/bootstrap_barrio/templates/layout/page.html.twig', Array)
Drupal\Core\Theme\ThemeManager->render('page', Array)
Drupal\Core\Render\Renderer->doRender(Array, )
Drupal\Core\Render\Renderer->render(Array)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1)
__TwigTemplate_df05244faca2f5ca5a1365e71348b8af3ab67d4d2e64686c649ed6460e498bf3->doDisplay(Array, Array)
Twig_Template->displayWithErrorHandling(Array, Array)
Twig_Template->display(Array)
Twig_Template->render(Array)
twig_render_template('themes/bootstrap_barrio/templates/layout/html.html.twig', Array)
Drupal\Core\Theme\ThemeManager->render('html', Array)
Drupal\Core\Render\Renderer->doRender(Array, )
Drupal\Core\Render\Renderer->render(Array)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

I changed settings inside the block and also moved it into different regions but nothing worked it completly crashed the site.

Here is what was actually rendered in HTML:

<body class="layout-one-sidebar layout-sidebar-first user-logged-in path-frontpage">
<head-placeholder token="DP7vUi2cXl_-HSiDUfdYcEIots0uBdyDQrgPJmjmb2VkF6ax-naM1g872Oa_e3-eYDVvRnSnmQ">
<title></title>
<css-placeholder token="DP7vUi2cXl_-HSiDUfdYcEIots0uBdyDQrgPJmjmb2VkF6ax-naM1g872Oa_e3-eYDVvRnSnmQ">
<js-placeholder token="DP7vUi2cXl_-HSiDUfdYcEIots0uBdyDQrgPJmjmb2VkF6ax-naM1g872Oa_e3-eYDVvRnSnmQ">
<a class="visually-hidden focusable skip-link" href="#main-content"> Skip to main content </a>
<div id="toolbar-administration" class="toolbar" aria-label="Site administration toolbar" role="group">
<nav id="toolbar-bar" class="toolbar-bar clearfix" aria-label="Toolbar items" role="navigation">
<h2 class="visually-hidden">Toolbar items</h2>
<div class="hidden home-toolbar-tab toolbar-tab">
<div class="toolbar-tab">
<div class="toolbar-tab">
<div class="hidden contextual-toolbar-tab toolbar-tab">
<div class="toolbar-tab">
</nav>
</div>
<div id="page-wrapper">
<div id="page">
<header id="header" class="header" aria-label="Site header" role="banner">
<nav id="navbar-top" class="navbar navbar-light bg-primary">
<div class="section container-fluid clearfix">
<div class="navbar-nav">
<div id="block-customsearchform" class="custom-search-block-form contextual-region block block-custom-search" aria-describedby="custom-search-form" data-drupal-selector="custom-search-block-form" role="search">
<h2 id="custom-search-form">Custom Search form</h2>
<div data-contextual-id="block:block=customsearchform:langcode=en"></div>
<div class="container-inline content">
The website encountered an unexpected error. Please try again later.
<br>
<em class="placeholder">Error</em>
: Call to undefined method Drupal\Component\Render\HtmlEscapedText::render() in
<em class="placeholder">bootstrap_barrio_preprocess_form_element()</em>
(line
<em class="placeholder">284</em>
of
<em class="placeholder">themes/bootstrap_barrio/bootstrap_barrio.theme</em>
).
<pre class="backtrace">bootstrap_barrio_preprocess_form_element(Array, 'form_element', Array) Drupal\Core\Theme\ThemeManager->render('form_element', Array) Drupal\Core\Render\Renderer->doRender(Array) Drupal\Core\Render\Renderer->doRender(Array, ) Drupal\Core\Render\Renderer->render(Array) Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) __TwigTemplate_4c69e5991f3e160b935047dfe4777706db635ab67265fa6f4ec5c39794e17709->block_content(Array, Array) Twig_Template->displayBlock('content', Array, Array) __TwigTemplate_4c69e5991f3e160b935047dfe4777706db635ab67265fa6f4ec5c39794e17709->doDisplay(Array, Array) Twig_Template->displayWithErrorHandling(Array, Array) Twig_Template->display(Array) Twig_Template->render(Array) twig_render_template('themes/bootstrap_barrio/templates/block/block.html.twig', Array) Drupal\Core\Theme\ThemeManager->render('block', Array) Drupal\Core\Render\Renderer->doRender(Array) Drupal\Core\Render\Renderer->doRender(Array, ) Drupal\Core\Render\Renderer->render(Array) Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) __TwigTemplate_4eda0ce75fcd4d7c7bfea8acfbaae4f24ee45e1495f6c6cfc1fc2dfc1d49ff2b->block_head(Array, Array) Twig_Template->displayBlock('head', Array, Array) __TwigTemplate_4eda0ce75fcd4d7c7bfea8acfbaae4f24ee45e1495f6c6cfc1fc2dfc1d49ff2b->doDisplay(Array, Array) Twig_Template->displayWithErrorHandling(Array, Array) Twig_Template->display(Array) Twig_Template->render(Array) twig_render_template('themes/bootstrap_barrio/templates/layout/page.html.twig', Array) Drupal\Core\Theme\ThemeManager->render('page', Array) Drupal\Core\Render\Renderer->doRender(Array, ) Drupal\Core\Render\Renderer->render(Array) Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) __TwigTemplate_df05244faca2f5ca5a1365e71348b8af3ab67d4d2e64686c649ed6460e498bf3->doDisplay(Array, Array) Twig_Template->displayWithErrorHandling(Array, Array) Twig_Template->display(Array) Twig_Template->render(Array) twig_render_template('themes/bootstrap_barrio/templates/layout/html.html.twig', Array) Drupal\Core\Theme\ThemeManager->render('html', Array) Drupal\Core\Render\Renderer->doRender(Array, ) Drupal\Core\Render\Renderer->render(Array) Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) Stack\StackedHttpKernel->handle(Object, 1, 1) Drupal\Core\DrupalKernel->handle(Object) </pre>
</div>
</div>
</div>
</div>
</nav>
</header>
</div>
</div>
</js-placeholder>
</css-placeholder>
</head-placeholder>
</body>

I hope this make sense and I have created an issue in the right place.

Comments

staulien created an issue. See original summary.

staulien’s picture

Issue summary: View changes
hatuhay’s picture

The way custom_search is altering the confirm conflicts with this function:

<?php
function bootstrap_barrio_preprocess_form_element(&$variables) {
  if (is_object($variables['label']['#title'])) {
    $variables['input_title'] = $variables['label']['#title']->render();
  }
  $variables['input_attributes'] = new Attribute($variables['element']['#attributes']);
}
?>

For some reason the render() function is not declared on $variables['label']['#title'].
Please with this explanation open a issue on custom_search module, linking with this one.
Let me know any updates.

hatuhay’s picture

Status: Active » Postponed (maintainer needs more info)
staulien’s picture

I have created an issue with the maintainer of the module. ISSUE LINK

Thanks for you very quick resonse and solution!

mario steinitz’s picture

We're maintaining the custom_search module and found the checkboxes and radios are not rendered properly with the bootstrap_barrio theme. Therefore we adapted our local test version of the bootstrap_barrio theme to letting it render the checkbox and radio label within the form_element template, not the form label template (basically an adapted version of the label pre-process function integrated within the form element pre-processing):

bootstrap_barrio.theme:

function bootstrap_barrio_preprocess_form_element(&$variables) {
  if (is_object($variables['label']['#title']) && method_exists($variables['label']['#title'], 'render')) {
    $variables['input_title'] = $variables['label']['#title']->render();
  }
  $variables['input_attributes'] = new Attribute($variables['element']['#attributes']);

  // Whether the form element is a checkbox or a radio element.
  if ($variables['type'] == 'checkbox' || $variables['type'] == 'radio') {
    // The label will be rendered within the form element template, so we
    // have to alter the label settings.
    $label = [];
    
    $element = $variables['label'];

    // If title and required marker are both empty, output no label.
    if (isset($element['#title']) && $element['#title'] !== '') {
      $label['title'] = ['#markup' => $element['#title']];
    }

    // Pass elements title_display to template.
    $label['title_display'] = $element['#title_display'];
    $label['attributes'] = new Attribute();

    // A #for property of a dedicated #type 'label' element as precedence.
    if (!empty($element['#for'])) {
      $label['attributes']['for'] = $element['#for'];
      // A custom #id allows the referenced form input element to refer back to
      // the label element; e.g., in the 'aria-labelledby' attribute.
      if (!empty($element['#id'])) {
        $label['attributes']['id'] = $element['#id'];
      }
    }
    // Otherwise, point to the #id of the form input element.
    elseif (!empty($element['#id'])) {
      $label['attributes']['for'] = $element['#id'];
    }

    // Pass elements required to template.
    $label['required'] = !empty($element['#required']) ? $element['#required'] : NULL;

    // Replace the element label.
    $variables['label'] = $label;
  }
}

templates/form/form-element.html.twig:

[...]
{%
  set label_classes = [
    label.title_display == 'after' ? 'option',
    label.title_display == 'invisible' ? 'visually-hidden',
    label.required ? 'js-form-required',
    label.required ? 'form-required',
  ]
%}
{% if type in ['checkbox', 'radio'] %}
  <div{{ attributes.addClass(classes) }}>
    {% if prefix is not empty %}
      <span class="field-prefix">{{ prefix }}</span>
    {% endif %}
    {% if description_display == 'before' and description.content %}
      <div{{ description.attributes }}>
        {{ description.content }}
      </div>
    {% endif %}
    <label{{ label.attributes }}>
      {% if label.title_display == 'before' %}
        {{ label.title }}&nbsp;
      {% endif %}
      <input{{ input_attributes }}>
      {% if label.title_display == 'after' %}
        &nbsp;{{ label.title }}
      {% endif %}
    </label>
    {% if suffix is not empty %}
      <span class="field-suffix">{{ suffix }}</span>
    {% endif %}
    {% if errors %}
      <div class="alert alert-danger" role="alert">
        <strong>{{ errors }}</strong>
      </div>
    {% endif %}
    {% if description_display in ['after', 'invisible'] and description.content %}
      <small{{ description.attributes.addClass(description_classes) }}>
        {{ description.content }}
      </small>
    {% endif %}
  </div>
  {% else %}
[...]

I did not attach a patch file. But the above code should get it working.

  • hatuhay committed dd7b6c7 on 8.x-4.x
    Issue #2668298: Custom Search Module Conflict.
    
hatuhay’s picture

Status: Postponed (maintainer needs more info) » Fixed

Thanks Mario,
Add he end the solution was simple:

function bootstrap_barrio_preprocess_form_element(&$variables) {
  if ( is_object($variables['label']['#title']) ) {
    $variables['input_title'] = $variables['label']['#title']->render();
  }
  else {
    $variables['input_title'] = $variables['label']['#title'];
  }
  $variables['input_attributes'] = new Attribute($variables['element']['#attributes']);
}
mario steinitz’s picture

Your above solution may work to show the label texts, but it leaves the rendered label tag of your form element template without context-related attributes (as 'class', 'for' or 'id').

The label won't be pre-processed by form.inc's template_preprocess_form_element_label() and your template also does not take any additional label attributes into account.

A good example where this would be required is a custom module of ours that replaces the browsers' standard checkboxes and radios using CSS by adding according classes to the wrapping labels within a form pre-processing.

Therefore we decided for this longer version I posted above.

Additionally, during our tests we found that the label property of the form_element variables may be an object as well that does not have the render() method. (I can't tell for sure which object it was. There are no notes on that.) Therefore the
if (is_object($variables['label']['#title']) && method_exists($variables['label']['#title'], 'render')) { [...] }
in our example.

hatuhay’s picture

Status: Fixed » Needs work

OK
Got the idea, bootstrap_barrio is missing the label preprocess and it is not processing the label object.
Good I will use your long version as it seems to be the right way.
Thanks!!

hatuhay’s picture

Status: Needs work » Closed (works as designed)
toomanynights’s picture

Status: Closed (works as designed) » Needs work

Hi there,

I'm sorry for reopening, but is this indeed fixed?
Custom Search module still doesn't work with Barrio..

hatuhay’s picture

Status: Needs work » Closed (won't fix)