You are here

public function WebformSubmissionLimitBlock::build in Webform 6.x

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

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

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

Class

WebformSubmissionLimitBlock
Provides a 'Webform submission limit' block.

Namespace

Drupal\webform\Plugin\Block

Code

public function build() {
  $build = [];
  if ($this->configuration['content']) {
    $build['content'] = WebformHtmlEditor::checkMarkup($this
      ->replaceTokens($this->configuration['content']));
  }
  if ($this->configuration['progress_bar']) {
    $total = $this
      ->getTotal();
    $limit = $this
      ->getLimit();
    $build['progress_bar'] = [
      '#theme' => 'progress_bar',
      '#percent' => round($total / $limit * 100),
    ];
    if ($message = $this->configuration['progress_bar_message']) {
      $build['progress_bar']['#message']['#markup'] = $this
        ->replaceTokens($message);
    }
    if ($label = $this->configuration['progress_bar_label']) {
      $build['progress_bar']['#label'] = $this
        ->replaceTokens($label);
    }
  }
  $build['#attached']['library'][] = 'webform/webform.block.submission_limit';
  return $build;
}