1

I am attempting to write a simple webform handler to add to the end of a multi-step webform, ultimately to generate a barcode with the submitted data. I've had success with other handlers on single step forms but it looks like the handler causes the wizard form to freeze and not progress to the next step.

My suspicion is that I'm missing something in my plugin code but I can't seem to find an answer to the problem in similar issues.

So far there's no functionality attempted in the handler because the form freezes on the first step.

Ultimately I only need this handler to fire upon final submission of my form.

I'm trying to test for the forms state with $webform_submission->getState() but I can't seem to get it right

  public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
   
   $state = $webform_submission->getWebform()->getSetting('results_disabled') ? WebformSubmissionInterface::STATE_COMPLETED : $webform_submission->getState();
    if ($this->configuration['states'] && in_array($state, $this->configuration['states'])) {
       //do something
      
    }
  }
3
  • Any errors in /admin/reports/dblog ? – No Sssweat Aug 21 '20 at 1:29
  • HI. No Errors showing. I've tried both with and without ajax and either way the form just won't progress when I hit the next button. Doesn't trigger any activity from the handler either. – Allen Barnett Aug 21 '20 at 12:59
  • Turns out I couldn't use var_dump() to debug. I needed to find the serial of the submitted webform and var_dump was causing the form to crash ... I used drupal_set_message() to dump variables instead and the handler seems to work fine. – Allen Barnett Aug 24 '20 at 17:14
1

Hopefully this will help someone out there but this is the code I finally got working. It takes the serial value from a webform submission and writes a Png barcode for use in emails. I'm using the Barcodes Module for Drupal 8.

use Com\Tecnick\Barcode\Barcode as BarcodeGenerator;

class BarcodeHandler extends WebformHandlerBase {
  /**
   * {@inheritdoc}
   * Write PNG barcode for registration emails
   */
 public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
   $regId = $webform_submission->serial();
   $type = 'C39';
   $barcode_file = 'registration/barcodes/' . $regId . '.png';
   $barcode = new BarcodeGenerator();
   $barcode_obj = $barcode->getBarcodeObj($type, $regId, 250, 50, 'black');

   file_put_contents($barcode_file, $barcode_obj->getPngData());
      
  }
}   

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.