Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 460 characters in body
Source Link
Prestosaurus
  • 2.1k
  • 1
  • 14
  • 29

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);
  }
}

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);
  }
}

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?

deleted 187 characters in body
Source Link
Prestosaurus
  • 2.1k
  • 1
  • 14
  • 29

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.

Looks like you can query webforms with a condition on category:

\Drupal::entityQuery('webform')->condition('category', 'category_name')

How do you get this value in preprocess? Maybe I need a different hook?


Edit:Success! (though not in preprocess)

Inside a custom webform Handler:handler using the ->get() method.

class CustomHandler extends WebformHandlerBase {
  public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
  kint(  $webformCategory = $webform_submission->getWebform()->get('category');
    array_push($form['#attributes']['class'], $webformCategory);
  }
}

I see an array key for category, but it's protected and I don't see an available method to retrieve it.

If I could access this value in alterForm() I think I could add the class like: array_push($form['#attributes']['class'], $webformCategory);

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.

Looks like you can query webforms with a condition on category:

\Drupal::entityQuery('webform')->condition('category', 'category_name')

How do you get this value in preprocess? Maybe I need a different hook?


Edit:

Inside a custom webform Handler:

public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
  kint($webform_submission->getWebform());
}

I see an array key for category, but it's protected and I don't see an available method to retrieve it.

If I could access this value in alterForm() I think I could add the class like: array_push($form['#attributes']['class'], $webformCategory);

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);
  }
}
added 495 characters in body
Source Link
Prestosaurus
  • 2.1k
  • 1
  • 14
  • 29

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.

Looks like you can query webforms with a condition on category:

\Drupal::entityQuery('webform')->condition('category', 'category_name')

How do you get this value in preprocess? Maybe I need a different hook?


Edit:

Inside a custom webform Handler:

public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
  kint($webform_submission->getWebform());
}

I see an array key for category, but it's protected and I don't see an available method to retrieve it.

If I could access this value in alterForm() I think I could add the class like: array_push($form['#attributes']['class'], $webformCategory);

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.

Looks like you can query webforms with a condition on category:

\Drupal::entityQuery('webform')->condition('category', 'category_name')

How do you get this value in preprocess? Maybe I need a different hook?

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.

Looks like you can query webforms with a condition on category:

\Drupal::entityQuery('webform')->condition('category', 'category_name')

How do you get this value in preprocess? Maybe I need a different hook?


Edit:

Inside a custom webform Handler:

public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
  kint($webform_submission->getWebform());
}

I see an array key for category, but it's protected and I don't see an available method to retrieve it.

If I could access this value in alterForm() I think I could add the class like: array_push($form['#attributes']['class'], $webformCategory);

Source Link
Prestosaurus
  • 2.1k
  • 1
  • 14
  • 29
Loading