entity_generic-8.x-3.x-dev/src/Generic/EntityArchivedTrait.php

src/Generic/EntityArchivedTrait.php
<?php

namespace Drupal\entity_generic\Generic;

/**
 * Implements archived status functionality.
 */
trait EntityArchivedTrait {

  /**
   * {@inheritdoc}
   */
  public function isArchived() {
    return (bool) $this->getEntityKey('archived');
  }

  /**
   * {@inheritdoc}
   */
  public function getArchived() {
    return (bool) $this->getEntityKey('archived');
  }

  /**
   * {@inheritdoc}
   */
  public function setArchived($archived) {
    $key = $this->getEntityType()->getKey('archived');
    $this->set($key, $archived ? 1 : 0);
    $this->getArchivedTime($archived ? \Drupal::time()->getRequestTime() : 0);

    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getArchivedTime() {
    $key = $this->getEntityType()->getKey('archived');

    return $this->get($key . '_time')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setArchivedTime($timestamp) {
    $key = $this->getEntityType()->getKey('archived');
    $this->set($key . '_time', $timestamp);

    return $this;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc