I am trying to get the Category name (from the General form settings) for webforms in a preprocess function, ultimately to add as a class to the webform wrapper.
MYMODULE.module:
function MYMODULE_preprocess_webform(&$variables) {
kint($variables);
}
Right now I don't see a "category" value in the array structure.
How do you get this value in preprocess? Maybe I need a different hook?
Success! (though not in preprocess)
Inside a custom handler using the ->get()
method.
class CustomHandler extends WebformHandlerBase {
public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
$webformCategory = $webform_submission->getWebform()->get('category');
array_push($form['#attributes']['class'], $webformCategory);
}
}