0

I'm trying to create a custom webform handler. I'd like to be able to attach my handler to any webform and have it display the message 'xyz' when the (multi step wizard) form is finally submitted. I have this file in my custom module at: my_module/src/Plugin/WebformHandler/PostWebformHandler.php.

<?php

namespace Drupal\test_b\Plugin\WebformHandler;

use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionInterface;

/**
 * Webform test b handler.
 *
 * @WebformHandler(
 *   id = "test_b",
 *   label = @Translation("Test B"),
 *   category = @Translation("Test B"),
 *   description = @Translation("Test B webform submission handler."),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
 * )
 */
class TestBWebformHandler extends WebformHandlerBase {

  /**
   * {@inheritdoc}
   */
  public function preSave(WebformSubmissionInterface $webform_submission) {
    \Drupal::messenger()->addMessage(t('xyz'));
  }

}

On navigating to my Webform settings, I see:

enter image description here

but when I click Add handler for Test B it does not attach to my form handlers?

enter image description here

  • 1
    The file and class names don't match (they need to) – Clive Nov 23 '18 at 13:38
0

The above code works. My mistake was in the naming of things. Name all files, classes etc. foo and it will attach.

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.