function webform_bootstrap_preprocess_fieldset in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_bootstrap/webform_bootstrap.module \webform_bootstrap_preprocess_fieldset()
Implements template_preprocess_fieldset().
File
- modules/
webform_bootstrap/ webform_bootstrap.module, line 163 - Helps support Webform to Bootstrap integration.
Code
function webform_bootstrap_preprocess_fieldset(&$variables) {
if (!_webform_bootstrap_is_active_theme()) {
return;
}
// Make sure that the core/modules/system/templates/fieldset.html.twig
// template is being used because this the template that we are fixing.
// Caching the info just-in-case there are a lot of fieldsets.
static $is_system_fieldset;
if (!isset($is_system_fieldset)) {
/** @var \Drupal\Core\Utility\ThemeRegistry $theme_registry */
$theme_registry = \Drupal::service('theme.registry')
->getRuntime();
$info = $theme_registry
->get('fieldset');
$is_system_fieldset = $info['path'] === 'core/modules/system/templates' ? TRUE : FALSE;
}
if (!$is_system_fieldset) {
return;
}
// Style fieldset error messages to match form element error messages.
// @see form-element.html.twig
if (!empty($variables['errors'])) {
$variables['errors'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'form-item--error-message',
'alert',
'alert-danger',
'alert-sm',
],
],
'content' => [
'#markup' => $variables['errors'],
],
];
}
}