You are here

protected function WebformSubmissionForm::overrideSettings in Webform 6.x

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

Override webform settings for the webform submission.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

2 calls to WebformSubmissionForm::overrideSettings()
WebformSubmissionForm::buildEntity in src/WebformSubmissionForm.php
Builds an updated entity object based upon the submitted form values.
WebformSubmissionForm::setEntity in src/WebformSubmissionForm.php
This is the best place to override an entity form's default settings because it is called immediately after the form object is initialized.

File

src/WebformSubmissionForm.php, line 461

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function overrideSettings(WebformSubmissionInterface $webform_submission) {
  $webform = $webform_submission
    ->getWebform();

  // Invoke override settings which resets the webform settings.
  $webform
    ->invokeHandlers('overrideSettings', $webform_submission);

  // Look for ?_webform_dialog=1 which enables Ajax support when this form is
  // opened in dialog.
  // @see webform.dialog.js
  //
  // Must be called after WebformHandler::overrideSettings which resets all
  // overridden settings.
  // @see \Drupal\webform\Entity\Webform::invokeHandlers
  if ($this
    ->getRequest()->query
    ->get('_webform_dialog') && !$webform
    ->getSetting('ajax', TRUE)) {
    $webform
      ->setSettingOverride('ajax', TRUE);
  }

  // If share page (i.e. /webform_share/{webform}), enable Ajax support
  // when this form is embedded in an iframe.
  if ($this
    ->isSharePage() && !$webform
    ->getSetting('ajax', TRUE)) {
    $webform
      ->setSettingOverride('ajax', TRUE);
  }

  // Apply source entity open/close state to the webform before
  // it is rendered.
  $source_entity = $webform_submission
    ->getSourceEntity();
  if ($webform
    ->isOpen() && $source_entity && $source_entity instanceof FieldableEntityInterface) {
    foreach ($source_entity
      ->getFieldDefinitions() as $fieldName => $fieldDefinition) {
      if ($fieldDefinition
        ->getType() === 'webform') {
        $item = $source_entity
          ->get($fieldName);
        if ($item->target_id === $webform
          ->id()) {
          $webform
            ->setOverride()
            ->set('open', $item->open)
            ->set('close', $item->close)
            ->setStatus($item->status);
        }
      }
    }
  }
}