You are here

protected function WebformSubmissionListBuilder::buildFilterForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionListBuilder.php \Drupal\webform\WebformSubmissionListBuilder::buildFilterForm()

Build the filter form.

Return value

array A render array representing the filter form.

1 call to WebformSubmissionListBuilder::buildFilterForm()
WebformSubmissionListBuilder::buildEntityList in src/WebformSubmissionListBuilder.php
Build the webform submission entity list.

File

src/WebformSubmissionListBuilder.php, line 638

Class

WebformSubmissionListBuilder
Provides a list controller for webform submission entity.

Namespace

Drupal\webform

Code

protected function buildFilterForm() {

  // State options.
  $state_options = [
    '' => $this
      ->t('All [@total]', [
      '@total' => $this
        ->getTotal(NULL, NULL, $this->sourceEntityTypeId),
    ]),
    static::STATE_STARRED => $this
      ->t('Starred [@total]', [
      '@total' => $this
        ->getTotal(NULL, static::STATE_STARRED, $this->sourceEntityTypeId),
    ]),
    static::STATE_UNSTARRED => $this
      ->t('Unstarred [@total]', [
      '@total' => $this
        ->getTotal(NULL, static::STATE_UNSTARRED, $this->sourceEntityTypeId),
    ]),
    static::STATE_LOCKED => $this
      ->t('Locked [@total]', [
      '@total' => $this
        ->getTotal(NULL, static::STATE_LOCKED, $this->sourceEntityTypeId),
    ]),
    static::STATE_UNLOCKED => $this
      ->t('Unlocked [@total]', [
      '@total' => $this
        ->getTotal(NULL, static::STATE_UNLOCKED, $this->sourceEntityTypeId),
    ]),
  ];

  // Add draft to state options.
  if (!$this->webform || $this->webform
    ->getSetting('draft') !== WebformInterface::DRAFT_NONE) {
    $state_options += [
      static::STATE_COMPLETED => $this
        ->t('Completed [@total]', [
        '@total' => $this
          ->getTotal(NULL, static::STATE_COMPLETED, $this->sourceEntityTypeId),
      ]),
      static::STATE_DRAFT => $this
        ->t('Draft [@total]', [
        '@total' => $this
          ->getTotal(NULL, static::STATE_DRAFT, $this->sourceEntityTypeId),
      ]),
    ];
  }

  // Source entity options.
  if ($this->webform && !$this->sourceEntity) {

    // < 100 source entities a select menuwill be displayed.
    // > 100 source entities an autocomplete input will be displayed.
    $source_entity_total = $this->storage
      ->getSourceEntitiesTotal($this->webform);
    if ($source_entity_total < 100) {
      $source_entity_options = $this->storage
        ->getSourceEntitiesAsOptions($this->webform);
      $source_entity_default_value = $this->sourceEntityTypeId;
    }
    elseif ($this->sourceEntityTypeId && strpos($this->sourceEntityTypeId, ':') !== FALSE) {
      $source_entity_options = $this->webform;
      try {
        list($source_entity_type, $source_entity_id) = explode(':', $this->sourceEntityTypeId);
        $source_entity = $this->entityTypeManager
          ->getStorage($source_entity_type)
          ->load($source_entity_id);
        $source_entity_default_value = $source_entity
          ->label() . " ({$source_entity_type}:{$source_entity_id})";
      } catch (\Exception $exception) {
        $source_entity_default_value = '';
      }
    }
    else {
      $source_entity_options = $this->webform;
      $source_entity_default_value = '';
    }
  }
  else {
    $source_entity_options = NULL;
    $source_entity_default_value = '';
  }
  return \Drupal::formBuilder()
    ->getForm('\\Drupal\\webform\\Form\\WebformSubmissionFilterForm', $this->keys, $this->state, $state_options, $source_entity_default_value, $source_entity_options);
}