You are here

public function YamlFormSubmissionController::sticky in YAML Form 8

Toggle form submission sticky.

Parameters

\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.

Return value

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

1 string reference to 'YamlFormSubmissionController::sticky'
yamlform.routing.yml in ./yamlform.routing.yml
yamlform.routing.yml

File

src/Controller/YamlFormSubmissionController.php, line 107

Class

YamlFormSubmissionController
Provides route responses for form submissions.

Namespace

Drupal\yamlform\Controller

Code

public function sticky(YamlFormSubmissionInterface $yamlform_submission) {

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

  // Get state.
  $state = $yamlform_submission
    ->isSticky() ? 'on' : 'off';
  $response = new AjaxResponse();
  $response
    ->addCommand(new HtmlCommand('#yamlform-submission-' . $yamlform_submission
    ->id() . '-sticky', new FormattableMarkup('<span class="yamlform-icon yamlform-icon-sticky yamlform-icon-sticky--@state"></span>', [
    '@state' => $state,
  ])));
  return $response;
}