entity_generic-8.x-3.x-dev/src/Generic/EntityDeletedTrait.php
src/Generic/EntityDeletedTrait.php
<?php
namespace Drupal\entity_generic\Generic;
/**
* Implements "mark as deleted" flag functionality.
*/
trait EntityDeletedTrait {
/**
* {@inheritdoc}
*/
public function isDeleted() {
return (bool) $this->getEntityKey('flag_deleted');
}
/**
* {@inheritdoc}
*/
public function getDeleted() {
return (bool) $this->getEntityKey('flag_deleted');
}
/**
* {@inheritdoc}
*/
public function setDeleted($flag_deleted) {
$key = $this->getEntityType()->getKey('flag_deleted');
$this->set($key, $flag_deleted ? 1 : 0);
$this->setDeletedTime($flag_deleted ? \Drupal::time()->getRequestTime() : 0);
return $this;
}
/**
* {@inheritdoc}
*/
public function getDeletedTime() {
$key = $this->getEntityType()->getKey('flag_deleted');
return $this->get($key . '_time')->value;
}
/**
* {@inheritdoc}
*/
public function setDeletedTime($timestamp) {
$key = $this->getEntityType()->getKey('flag_deleted');
$this->set($key . '_time', $timestamp);
return $this;
}
}
