I have a custom form built with Form API that I am trying to add a class to on the form tag.
In the buildForm
method, I have:
$form['#attributes']['class'][] = 'hl__single-input-form__form';
But the class doesn't appear on the form tag. Instead, the class appears on the div wrapper for the block that outputs the form.
In the block, the build
method has:
/**
* {@inheritdoc}
*/
public function build() {
return $this->formBuilder->getForm('\Drupal\harlib_newsletter_signup\Form\NewsletterSignup');
}
The only way I have been able to solve this is with a custom twig file with the following:
<section class="hl__single-input-form">
<form{{ attributes.addClass('hl__single-input-form__form') }}>
{{ children }}
</form>
</section>
But the twig shouldn't be necessary. I also notice that the form id as a css class also goes on the block wrapper, too. What is happening here?