entity_generic-8.x-3.x-dev/src/Generic/EntityApprovedTrait.php
src/Generic/EntityApprovedTrait.php
<?php namespace Drupal\entity_generic\Generic; /** * Implements approved status functionality. */ trait EntityApprovedTrait { /** * {@inheritdoc} */ public function isApproved() { return (bool) $this->getEntityKey('approved'); } /** * {@inheritdoc} */ public function getApproved() { return (bool) $this->getEntityKey('approved'); } /** * {@inheritdoc} */ public function setApproved($approved) { $key = $this->getEntityType()->getKey('approved'); $this->set($key, $approved ? 1 : 0); $this->setApprovedTime($approved ? \Drupal::time()->getRequestTime() : 0); return $this; } /** * {@inheritdoc} */ public function getApprovedTime() { $key = $this->getEntityType()->getKey('approved'); return $this->get($key . '_time')->value; } /** * {@inheritdoc} */ public function setApprovedTime($timestamp) { $key = $this->getEntityType()->getKey('approved'); $this->set($key . '_time', $timestamp); return $this; } }