You are here

public static function WebformSubmissionForm::isOpen in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::isOpen()

Programmatically check that a webform is open to new submissions.

Parameters

\Drupal\webform\WebformInterface $webform: A webform.

Return value

array|bool Return TRUE if the webform is open to new submissions else returns an error message.

See also

\Drupal\webform\WebformSubmissionForm::getCustomForm

2 calls to WebformSubmissionForm::isOpen()
WebformDevelSubmissionApiForm::validateForm in modules/webform_devel/src/Form/WebformDevelSubmissionApiForm.php
Form validation handler.
WebformSubmissionApiTest::testApi in tests/src/Functional/WebformSubmissionApiTest.php
Test webform API.

File

src/WebformSubmissionForm.php, line 3104

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

public static function isOpen(WebformInterface $webform) {
  $webform_submission = WebformSubmission::create([
    'webform_id' => $webform
      ->id(),
  ]);

  /** @var \Drupal\webform\WebformSubmissionForm $form_object */
  $form_object = \Drupal::entityTypeManager()
    ->getFormObject('webform_submission', 'add');
  $form_object
    ->setEntity($webform_submission);

  /** @var \Drupal\webform\WebformMessageManagerInterface $message_manager */
  $message_manager = \Drupal::service('webform.message_manager');
  $message_manager
    ->setWebformSubmission($webform_submission);

  // Check form is open.
  if ($webform
    ->isClosed()) {
    if ($webform
      ->isOpening()) {
      return $message_manager
        ->get(WebformMessageManagerInterface::FORM_OPEN_MESSAGE);
    }
    else {
      return $message_manager
        ->get(WebformMessageManagerInterface::FORM_CLOSE_MESSAGE);
    }
  }

  // Check total limit.
  if ($form_object
    ->checkTotalLimit()) {
    return $message_manager
      ->get(WebformMessageManagerInterface::LIMIT_TOTAL_MESSAGE);
  }

  // Check user limit.
  if ($form_object
    ->checkUserLimit()) {
    return $message_manager
      ->get(WebformMessageManagerInterface::LIMIT_USER_MESSAGE);
  }
  return TRUE;
}