You are here

protected function WebformSubmissionListBuilder::buildSubmissionViewsMenu in Webform 8.5

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

Build the submission views menu.

Return value

array A render array representing the submission views menu.

1 call to WebformSubmissionListBuilder::buildSubmissionViewsMenu()
WebformSubmissionListBuilder::render in src/WebformSubmissionListBuilder.php
Builds the entity listing as renderable array for table.html.twig.

File

src/WebformSubmissionListBuilder.php, line 589

Class

WebformSubmissionListBuilder
Provides a list controller for webform submission entity.

Namespace

Drupal\webform

Code

protected function buildSubmissionViewsMenu() {
  if (empty($this->submissionViews)) {
    return [];
  }
  $route_name = $this->routeMatch
    ->getRouteName();
  $route_parameters = $this->routeMatch
    ->getRawParameters()
    ->all();
  unset($route_parameters['submission_view']);
  $links = [];
  if (!$this
    ->isSubmissionViewResultsReplaced()) {
    $links['_default_'] = [
      'title' => $this
        ->t('Submissions'),
      'url' => Url::fromRoute($route_name, $route_parameters),
    ];
  }
  foreach ($this->submissionViews as $name => $submission_view) {
    $links[$name] = [
      'title' => $submission_view['title'],
      'url' => Url::fromRoute($route_name, $route_parameters + [
        'submission_view' => $name,
      ]),
    ];
  }

  // Only display the submission views menu when there is more than 1 link.
  if (count($links) <= 1) {
    return [];
  }

  // Make sure the current submission view is first.
  if ($this->submissionView) {
    $links = [
      $this->submissionView => $links[$this->submissionView],
    ] + $links;
  }
  $build = [];
  $build['submission_views'] = [
    '#type' => 'operations',
    '#links' => $links,
    '#prefix' => '<div class="webform-dropbutton webform-submission-views-dropbutton">',
    '#suffix' => '</div>' . ($this->submissionView ? '<p><hr/></p>' : ''),
  ];
  return $build;
}