entity_generic-8.x-3.x-dev/src/Plugin/Action/MarkDeletedAction.php
src/Plugin/Action/MarkDeletedAction.php
<?php
namespace Drupal\entity_generic\Plugin\Action;
use Drupal\Core\Action\Plugin\Action\EntityActionBase;
use Drupal\Core\Session\AccountInterface;
use Drupal\entity_generic\Entity\GenericInterface;
/**
* @Action(
* id = "entity:mark_deleted_action",
* label = @Translation("Mark entity as deleted"),
* deriver = "Drupal\entity_generic\Plugin\Action\Derivative\MarkDeletedActionDeriver",
* )
*/
class MarkDeletedAction extends EntityActionBase {
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity->setDeleted(GenericInterface::ENTITY_GENERIC_DELETED);
$entity->save();
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = $object->access('update', $account, TRUE);
return $return_as_object ? $result : $result->isAllowed();
}
}
