You are here

protected function WebformSubmissionLimitBlock::replaceTokens in Webform 8.5

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

Replace tokens in text.

Parameters

string|array $text: A string of text that may contain tokens.

Return value

string|array Text or array with tokens replaced.

1 call to WebformSubmissionLimitBlock::replaceTokens()
WebformSubmissionLimitBlock::build in src/Plugin/Block/WebformSubmissionLimitBlock.php
Builds and returns the renderable array for this block plugin.

File

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

Class

WebformSubmissionLimitBlock
Provides a 'Webform submission limit' block.

Namespace

Drupal\webform\Plugin\Block

Code

protected function replaceTokens($text) {

  // Replace [total] token.
  if (strpos($text, '[total]') !== FALSE) {
    $text = str_replace('[total]', $this
      ->getTotal(), $text);
  }

  // Replace [limit] token.
  if (strpos($text, '[limit]') !== FALSE) {
    $text = str_replace('[limit]', $this
      ->getLimit(), $text);
  }

  // Replace [remaining] token.
  if (strpos($text, '[remaining]') !== FALSE) {
    $text = str_replace('[remaining]', $this
      ->getLimit() - $this
      ->getTotal(), $text);
  }

  // Replace [interval] token.
  if (strpos($text, '[interval]') !== FALSE) {
    $text = str_replace('[interval]', $this
      ->getIntervalText(), $text);
  }

  // Replace webform tokens.
  return $this->tokenManager
    ->replace($text, $this
    ->getWebform());
}