class PreviewLinkHooks in Preview Link 8
Drupal hooks.
Hierarchy
- class \Drupal\preview_link\PreviewLinkHooks implements ContainerInjectionInterface
Expanded class hierarchy of PreviewLinkHooks
1 file declares its use of PreviewLinkHooks
- preview_link.module in ./
preview_link.module - Module file.
File
- src/
PreviewLinkHooks.php, line 12
Namespace
Drupal\preview_linkView source
class PreviewLinkHooks implements ContainerInjectionInterface {
/**
* Preview link storage.
*
* @var \Drupal\preview_link\PreviewLinkStorageInterface
*/
protected $previewLinkStorage;
/**
* Time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Calculates link expiry time.
*
* @var \Drupal\preview_link\LinkExpiry
*/
protected $linkExpiry;
/**
* PreviewLinkHooks constructor.
*
* @param \Drupal\preview_link\PreviewLinkStorageInterface $previewLinkStorage
* Preview link storage.
* @param \Drupal\Component\Datetime\TimeInterface $time
* Time service.
* @param \Drupal\preview_link\LinkExpiry $linkExpiry
* Calculates link expiry time.
*/
public function __construct(PreviewLinkStorageInterface $previewLinkStorage, TimeInterface $time, LinkExpiry $linkExpiry) {
$this->previewLinkStorage = $previewLinkStorage;
$this->time = $time;
$this->linkExpiry = $linkExpiry;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage('preview_link'), $container
->get('datetime.time'), $container
->get('preview_link.link_expiry'));
}
/**
* Implements hook_cron().
*
* @see \preview_link_cron()
*/
public function cron() {
$expireBeforeTime = $this->time
->getRequestTime() - $this->linkExpiry
->getLifetime();
$ids = $this->previewLinkStorage
->getQuery()
->condition('generated_timestamp', $expireBeforeTime, '<')
->execute();
// If there are no expired links then nothing to do.
if (!count($ids)) {
return;
}
$previewLinks = $this->previewLinkStorage
->loadMultiple($ids);
// Simply delete the preview links. A new one will be regenerated at a later
// date as required.
$this->previewLinkStorage
->delete($previewLinks);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PreviewLinkHooks:: |
protected | property | Calculates link expiry time. | |
PreviewLinkHooks:: |
protected | property | Preview link storage. | |
PreviewLinkHooks:: |
protected | property | Time service. | |
PreviewLinkHooks:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
PreviewLinkHooks:: |
public | function | Implements hook_cron(). | |
PreviewLinkHooks:: |
public | function | PreviewLinkHooks constructor. |