UnpublishUnit.php in Booking and Availability Management Tools for Drupal 8
File
modules/bat_unit/src/Plugin/Action/UnpublishUnit.php
View source
<?php
namespace Drupal\bat_unit\Plugin\Action;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;
class UnpublishUnit extends ActionBase {
public function execute($entity = NULL) {
$entity->status = 0;
$entity
->save();
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$access = $object
->access('update', $account, TRUE)
->andIf($object->status
->access('edit', $account, TRUE));
return $return_as_object ? $access : $access
->isAllowed();
}
}