You are here

class PreviewLinkExpiry in Preview Link 2.0.x

Same name and namespace in other branches
  1. 2.x src/PreviewLinkExpiry.php \Drupal\preview_link\PreviewLinkExpiry

Calculates link expiry time.

Hierarchy

Expanded class hierarchy of PreviewLinkExpiry

1 string reference to 'PreviewLinkExpiry'
preview_link.services.yml in ./preview_link.services.yml
preview_link.services.yml
1 service uses PreviewLinkExpiry
preview_link.link_expiry in ./preview_link.services.yml
Drupal\preview_link\PreviewLinkExpiry

File

src/PreviewLinkExpiry.php, line 12

Namespace

Drupal\preview_link
View source
class PreviewLinkExpiry {

  /**
   * Default expiry time in days.
   *
   * @var int
   */
  const DEFAULT_EXPIRY_DAYS = 7;

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * LinkExpiry constructor.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /**
   * Calculates default lifetime of a preview link.
   *
   * @return int
   *   Preview link in seconds.
   */
  public function getLifetime() : int {
    $days = $this->state
      ->get('preview_link_expiry_days', static::DEFAULT_EXPIRY_DAYS);
    return $days * 86400;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PreviewLinkExpiry::$state protected property The state service.
PreviewLinkExpiry::DEFAULT_EXPIRY_DAYS constant Default expiry time in days.
PreviewLinkExpiry::getLifetime public function Calculates default lifetime of a preview link.
PreviewLinkExpiry::__construct public function LinkExpiry constructor.