How to alter a Webform's settings before rendering a submission form
Last updated on
16 August 2017
This recipe shows how to dynamically alter a Webform's settings before rendering a submission form.
The below example demonstrates how to disable a Webform's preview button and tab when editing a submission.
use \Drupal\Core\Form\FormStateInterface;
use \Drupal\webform\WebformSubmissionInterface;
/**
* Implements hook_ENTITY_TYPE_prepare_form().
*/
function webform_webform_submission_prepare_form(WebformSubmissionInterface $webform_submission, $operation, FormStateInterface $form_state) {
// Only execute the below code if we are editing a submission.
if ($operation != 'edit') {
return;
}
// Get the submission's Webform.
$webform = $webform_submission->getWebform();
// Only disable the preview for the 'example_wizard' webform included
// in the webform_example.module.
if ($webform->id() == 'example_wizard') {
$webform->setSetting('preview', DRUPAL_DISABLED);
}
}
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion