-1

I have been trying to write a custom module for my webform where the access of a radio element (to approve or reject) is granted to the director's email (the submitted value of the email element in the beginning of the form by the requester).

When the requester submits the webform, the email handler will send a notification email to the director through [webform_submission:token-update-url], then the director clicks the link and choose the option in the update link then save the form.

I have tried two of the hook functions but none of them would work when I ran drush cr after updating the code.

function request_approval_form_alter(array &$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $value = $form_state->getValue('submitted_to');
  $currentUser = \Drupal::currentUser()->getAccountName;
  if ($form_id == 'ach_request') {
    if ($value === $currentUser) { 
      $form['approval_state_']['#access'] = TRUE;
    }
  }
}
function request_approval_webform_element_alter(array &$element, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {
  /** @var \Drupal\webform\WebformSubmissionForm $form_object */
  $form_object = $form_state->getFormObject();
  /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
  $webform_submission = $form_object->getEntity();
  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = $webform_submission->getWebform();

  $element['#attributes']['data-custom'] = '{custom data goes here}';

  $currentUser = \Drupal::currentUser()->getAccountName();

  if ($element['#webform_id'] === 'ach_request') {
    if ($element['#value']['submitted_to'] === $currentUser) {
      $element['#access']['submitted_to'] = TRUE;
    }
  }
}

Please help!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.