webform_test_alter_hooks.module in Webform 6.x
Same filename and directory in other branches
Support module for webform that tests form and element alter hooks.
File
tests/modules/webform_test_alter_hooks/webform_test_alter_hooks.moduleView source
<?php
/**
* @file
* Support module for webform that tests form and element alter hooks.
*/
use Drupal\Core\Form\FormStateInterface;
/******************************************************************************/
// Form hooks.
/******************************************************************************/
/**
* Implements hook_form_alter().
*/
function webform_test_alter_hooks_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (strpos($form_id, 'webform_') === 0) {
\Drupal::messenger()
->addStatus(t("@hook: '@form_id' executed.", [
'@hook' => 'hook_form_alter()',
'@form_id' => $form_id,
]), TRUE);
}
}
/**
* Implements hook_form_webform_submission_form_alter().
*/
function webform_test_alter_hooks_form_webform_submission_form_alter(array $form, FormStateInterface $form_state, $form_id) {
\Drupal::messenger()
->addStatus(t("@hook: '@form_id' executed.", [
'@hook' => 'hook_form_webform_submission_form_alter()',
'@form_id' => $form_id,
]), TRUE);
}
/**
* Implements hook_form_webform_submission_BASE_FORM_ID_form_alter().
*
* @see webform_form_alter()
* @see \Drupal\webform\WebformSubmissionForm::getBaseFormId
* @see \Drupal\Core\Form\FormBuilder::prepareForm
*/
function webform_test_alter_hooks_form_webform_submission_contact_form_alter(array $form, FormStateInterface $form_state, $form_id) {
\Drupal::messenger()
->addStatus(t("@hook: '@form_id' executed.", [
'@hook' => 'hook_form_webform_submission_BASE_FORM_ID_form_alter()',
'@form_id' => $form_id,
]), TRUE);
}
/**
* Implements hook_form_webform_submission_FORM_ID_form_alter().
*
* @see webform_form_alter()
* @see \Drupal\webform\WebformSubmissionForm::getFormId
* @see \Drupal\Core\Form\FormBuilder::prepareForm
*/
function webform_test_alter_hooks_form_webform_submission_contact_add_form_alter(array $form, FormStateInterface $form_state, $form_id) {
\Drupal::messenger()
->addStatus(t("@hook: '@form_id' executed.", [
'@hook' => 'hook_form_webform_submission_FORM_ID_form_alter()',
'@form_id' => $form_id,
]), TRUE);
}
/**
* Implements hook_form_webform_submission_FORM_ID_form_alter().
*
* @see webform_form_alter()
* @see \Drupal\webform\WebformSubmissionForm::getFormId
* @see \Drupal\Core\Form\FormBuilder::prepareForm
*/
function webform_test_alter_hooks_form_webform_submission_contact_node_1_add_form_alter(array $form, FormStateInterface $form_state, $form_id) {
\Drupal::messenger()
->addStatus(t("@hook: '@form_id' executed.", [
'@hook' => 'hook_form_webform_submission_FORM_ID_form_alter()',
'@form_id' => $form_id,
]), TRUE);
}
/**
* Implements hook_webform_submission_form_alter().
*
* @see \Drupal\webform\WebformSubmissionForm::buildForm
*/
function webform_test_alter_hooks_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
\Drupal::messenger()
->addStatus(t("@hook: '@form_id' executed.", [
'@hook' => 'hook_webform_submission_form_alter()',
'@form_id' => $form_id,
]), TRUE);
}
/******************************************************************************/
// Element hooks.
/******************************************************************************/
/**
* Implements hook_webform_element_alter().
*
* @see webform.api.php
* @see \Drupal\webform\WebformSubmissionForm::prepareElements
*/
function webform_test_alter_hooks_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
\Drupal::messenger()
->addStatus(t("@hook: '@webform_key' executed.", [
'@hook' => 'hook_webform_element_alter()',
'@webform_key' => $element['#webform_key'],
]), TRUE);
}
/**
* Implements hook_webform_element_ELEMENT_TYPE_alter().
*
* @see webform.api.php
* @see \Drupal\webform\WebformSubmissionForm::prepareElements
*/
function webform_test_alter_hooks_webform_element_email_alter(array &$element, FormStateInterface $form_state, array $context) {
\Drupal::messenger()
->addStatus(t("@hook: '@webform_key' executed.", [
'@hook' => 'hook_webform_element_ELEMENT_TYPE_alter()',
'@webform_key' => $element['#webform_key'],
]), TRUE);
}
Functions
Name | Description |
---|---|
webform_test_alter_hooks_form_alter | Implements hook_form_alter(). |
webform_test_alter_hooks_form_webform_submission_contact_add_form_alter | Implements hook_form_webform_submission_FORM_ID_form_alter(). |
webform_test_alter_hooks_form_webform_submission_contact_form_alter | Implements hook_form_webform_submission_BASE_FORM_ID_form_alter(). |
webform_test_alter_hooks_form_webform_submission_contact_node_1_add_form_alter | Implements hook_form_webform_submission_FORM_ID_form_alter(). |
webform_test_alter_hooks_form_webform_submission_form_alter | Implements hook_form_webform_submission_form_alter(). |
webform_test_alter_hooks_webform_element_alter | Implements hook_webform_element_alter(). |
webform_test_alter_hooks_webform_element_email_alter | Implements hook_webform_element_ELEMENT_TYPE_alter(). |
webform_test_alter_hooks_webform_submission_form_alter | Implements hook_webform_submission_form_alter(). |