You are here

public function YamlFormSubmissionListBuilder::__construct in YAML Form 8

Constructs a new EntityListBuilder object.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage class.

Overrides EntityListBuilder::__construct

File

src/YamlFormSubmissionListBuilder.php, line 137

Class

YamlFormSubmissionListBuilder
Provides a list controller for yamlform submission entity.

Namespace

Drupal\yamlform

Code

public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) {
  parent::__construct($entity_type, $storage);
  $this->requestHandler = \Drupal::service('yamlform.request');
  $this->keys = \Drupal::request()->query
    ->get('search');
  $this->state = \Drupal::request()->query
    ->get('state');
  list($this->yamlform, $this->sourceEntity) = $this->requestHandler
    ->getYamlFormEntities();
  $base_route_name = $this->yamlform ? $this->requestHandler
    ->getBaseRouteName($this->yamlform, $this->sourceEntity) : '';
  $this->account = \Drupal::routeMatch()
    ->getRouteName() == "{$base_route_name}.yamlform.user.submissions" ? \Drupal::currentUser() : NULL;
  $this->elementManager = \Drupal::service('plugin.manager.yamlform.element');

  /** @var YamlFormSubmissionStorageInterface $yamlform_submission_storage */
  $yamlform_submission_storage = $this
    ->getStorage();
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  if ($route_name == "{$base_route_name}.yamlform.results_table") {
    $this->columns = $yamlform_submission_storage
      ->getCustomColumns($this->yamlform, $this->sourceEntity, $this->account, TRUE);
    $this->sort = $yamlform_submission_storage
      ->getCustomSetting('sort', 'serial', $this->yamlform, $this->sourceEntity);
    $this->direction = $yamlform_submission_storage
      ->getCustomSetting('direction', 'desc', $this->yamlform, $this->sourceEntity);
    $this->limit = $yamlform_submission_storage
      ->getCustomSetting('limit', 50, $this->yamlform, $this->sourceEntity);
    $this->format = $yamlform_submission_storage
      ->getCustomSetting('format', $this->format, $this->yamlform, $this->sourceEntity);
    $this->customize = TRUE;
    if ($this->format['element_format'] == 'raw') {
      foreach ($this->columns as &$column) {
        $column['format'] = 'raw';
        if (isset($column['element'])) {
          $column['element']['#format'] = 'raw';
        }
      }
    }
  }
  else {
    $this->columns = $yamlform_submission_storage
      ->getDefaultColumns($this->yamlform, $this->sourceEntity, $this->account, FALSE);

    // Display the sid when show results from all forms.
    if ($route_name == 'entity.yamlform_submission.collection') {
      unset($this->columns['serial']);
      $this->columns['sid']['title'] = '#';
      $this->sort = 'sid';
    }
    else {
      unset($this->columns['sid']);
      $this->sort = 'serial';
    }
    $this->direction = 'desc';
    $this->limit = 50;
    $this->customize = FALSE;
  }
}