You are here

WebformSubmissionLockAction.php in Webform 8.5

Same filename and directory in other branches
  1. 6.x src/Plugin/Action/WebformSubmissionLockAction.php

File

src/Plugin/Action/WebformSubmissionLockAction.php
View source
<?php

namespace Drupal\webform\Plugin\Action;

use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;

/**
 * Locks a webform submission.
 *
 * @Action(
 *   id = "webform_submission_make_lock_action",
 *   label = @Translation("Lock submission"),
 *   type = "webform_submission"
 * )
 */
class WebformSubmissionLockAction extends ActionBase {

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL) {

    /** @var \Drupal\webform\WebformSubmissionInterface $entity */
    $entity
      ->setLocked(TRUE)
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {

    /** @var \Drupal\webform\WebformSubmissionInterface $object */
    $result = $object->locked
      ->access('edit', $account, TRUE)
      ->andIf($object
      ->access('update', $account, TRUE));
    return $return_as_object ? $result : $result
      ->isAllowed();
  }

}

Classes

Namesort descending Description
WebformSubmissionLockAction Locks a webform submission.