I am having a Webform where I need to programmatically use all data the user has input in the webform but without saving submissions.

In the webform settings, there is a setting about Disable saving of submissions but when I use the below function in my CustomHandler:

public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) { 
//...
}

this setting will become disabled with a message: This webform's submission handlers requires submissions to be saved to the database.

What function should I use in order to disable saving submission to the database ?

Thank you,

CommentFileSizeAuthor
#3 Settings.jpg25.81 KBc.e.a

Comments

C.E.A created an issue. See original summary.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

I am not completely following your question.

In your custom handler, you can set results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED, in the plugin's annotation.

c.e.a’s picture

StatusFileSize
new25.81 KB

Below is my CustomHandler.php file:

<?php

namespace Drupal\custom_module\Plugin\WebformHandler;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Serialization\Yaml;
use Drupal\Core\Form\FormStateInterface;

use Drupal\user\Entity\User;
use Drupal\node\Entity\Node;

use Drupal\webform\WebformInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\webformSubmissionInterface;
use Drupal\webform\Entity\WebformSubmission;

/**
 * Submissions should not be saved to the database.
 *
 * @WebformHandler(
 *   id = "Submissions should not be saved to the database",
 *   label = @Translation("Submissions should not be saved to the database"),
 *   category = @Translation("Create Entity"),
 *   description = @Translation("Submissions should not be saved to the database."),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED,
 * )
 */

class CustomHandler extends WebformHandlerBase {

  /**
   * {@inheritdoc}
   */

// Function to be fired on creating a new Webform submission.
public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {

// Get an array of the values from the submission.
    $values = $webform_submission->getData();

// ...

}

But if I visit the webform settings: /admin/structure/webform/manage/test_webform/settings

I will find:

Settings

Why I cannot Check [x] Disable saving of submissions ?

c.e.a’s picture

Status: Postponed (maintainer needs more info) » Needs work
jrockowitz’s picture

Status: Needs work » Postponed (maintainer needs more info)

You need to remove the submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED, from the handler annotation.

c.e.a’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Thank you, it worked