Prevent underscores from removing text? Drupal seems to be removing all text prior to an underscore in my form. This is in the Form.php file of my module implementing Google CSE, so I cannot change the attribute name.

if (array_key_exists('search_broadness', $get_results) &amp;&amp; $get_results['search_broadness'] == 'narrow') {
  $block .= 'data-as_sitesearch="' . $gcse_narrow_search_query . '"';
}
$form['search']['results'] = array(
  '#type' =&gt; 'item',
  '#markup' =&gt; $block,
  '#allowed_tags' =&gt; ['script', 'div'],
)


And this is the output, note that the data-as_sitesearch is shortened to sitesearch.

&lt;div class="gcse-searchresults-only" sitesearch="https://www.example.com/drupal8_gcse/"&gt;&lt;/div&gt;


The Drupal Google CSE module does not have this feature, so I cannot use that. #markup in Drupal 7 worked to get around this, but not in Drupal 8. Is there a workaround to bypass this sanitation?
I'm struggling to understand what that code is trying to do; I'm assuming your end goal is to render either this:

&lt;div class="gcse-searchresults-only"&gt;&lt;/div&gt;


Or this, if the condition passes:

&lt;div class="gcse-searchresults-only" data-as_sitesearch="https://www.example.com/drupal8_gcse/"&gt;&lt;/div&gt;


But I don't see how the code sample would ever to get to even the result in your question. There's no mention of a &lt;div&gt;, and if $block contains the opening &lt;div..., then you've forgotten to close the opening tag and provide a closing tag after concat'ing the attribute string.

To make the whole thing easier (and a bit cleaner), you can use html_tag instead:

$form['search']['results'] = [
  '#type' =&gt; 'html_tag',
  '#tag' =&gt; 'div',
  '#attributes' =&gt; ['class' =&gt; ['gcse-searchresults-only']],
  '#value' =&gt; '',
];

if (array_key_exists('search_broadness', $get_results) &amp;&amp; $get_results['search_broadness'] == 'narrow') {
  $form['search']['results']['#attributes']['data-as_sitesearch'] = $gcse_narrow_search_query;
}