You are here

protected function WebformSubmissionLimitBlock::getWebform in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/Block/WebformSubmissionLimitBlock.php \Drupal\webform\Plugin\Block\WebformSubmissionLimitBlock::getWebform()

Get the webform.

Return value

\Drupal\webform\WebformInterface|bool The webform or FALSE if the webform is not available.

3 calls to WebformSubmissionLimitBlock::getWebform()
WebformSubmissionLimitBlock::blockAccess in src/Plugin/Block/WebformSubmissionLimitBlock.php
Indicates whether the block should be shown.
WebformSubmissionLimitBlock::getTotal in src/Plugin/Block/WebformSubmissionLimitBlock.php
Get total number of submissions for selected limit type.
WebformSubmissionLimitBlock::replaceTokens in src/Plugin/Block/WebformSubmissionLimitBlock.php
Replace tokens in text.

File

src/Plugin/Block/WebformSubmissionLimitBlock.php, line 406

Class

WebformSubmissionLimitBlock
Provides a 'Webform submission limit' block.

Namespace

Drupal\webform\Plugin\Block

Code

protected function getWebform() {
  if (isset($this->webform)) {
    return $this->webform;
  }
  if ($this->configuration['webform_id']) {
    $this->webform = Webform::load($this->configuration['webform_id']) ?: FALSE;
  }
  else {
    $this->webform = $this->requestHandler
      ->getCurrentWebform() ?: FALSE;
  }

  // Apply overridden settings to the webform which requires
  // a temp webform submission.
  if ($this->webform) {

    /** @var \Drupal\webform\WebformSubmissionStorageInterface $webform_submission_storage */
    $webform_submission_storage = $this->entityTypeManager
      ->getStorage('webform_submission');
    $values = [
      'webform_id' => $this
        ->getWebform()
        ->id(),
    ];
    if ($source_entity = $this
      ->getSourceEntity()) {
      $values += [
        'entity_type' => $source_entity
          ->getEntityTypeId(),
        'entity_id' => $source_entity
          ->id(),
      ];
    }
    $temp_webform_submission = $webform_submission_storage
      ->create($values);
    $this->webform
      ->invokeHandlers('overrideSettings', $temp_webform_submission);
  }
  return $this->webform;
}