You are here

public function WebformSubmissionController::sticky in Webform 8.5

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

Toggle webform submission sticky.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

Return value

\Drupal\Core\Ajax\AjaxResponse An Ajax response that toggle the sticky icon.

1 string reference to 'WebformSubmissionController::sticky'
webform.routing.yml in ./webform.routing.yml
webform.routing.yml

File

src/Controller/WebformSubmissionController.php, line 80

Class

WebformSubmissionController
Provides route responses for Webform submissions.

Namespace

Drupal\webform\Controller

Code

public function sticky(WebformSubmissionInterface $webform_submission) {

  // Toggle sticky.
  $webform_submission
    ->setSticky(!$webform_submission
    ->isSticky())
    ->save();

  // Get selector.
  $selector = '#webform-submission-' . $webform_submission
    ->id() . '-sticky';
  $response = new AjaxResponse();

  // Update sticky.
  $response
    ->addCommand(new HtmlCommand($selector, static::buildSticky($webform_submission)));

  // Announce sticky status.
  $t_args = [
    '@label' => $webform_submission
      ->label(),
  ];
  $text = $webform_submission
    ->isSticky() ? $this
    ->t('@label flagged/starred.', $t_args) : $this
    ->t('@label unflagged/unstarred.', $t_args);
  $response
    ->addCommand(new AnnounceCommand($text));
  return $response;
}