Namespace
Drupal\rules\ContextProvider
File
-
src/ContextProvider/CurrentDateContext.php
View source
<?php
namespace Drupal\rules\ContextProvider;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\ContextProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class CurrentDateContext implements ContextProviderInterface {
use StringTranslationTrait;
protected $datetime;
public function __construct(TimeInterface $datetime) {
$this->datetime = $datetime;
}
public function getRuntimeContexts(array $unqualified_context_ids) {
$datetime = $this->datetime
->getCurrentTime();
$context_definition = new ContextDefinition('timestamp', $this->t('Current date'));
$context = new Context($context_definition, $datetime);
$result = [
'current_date' => $context,
];
return $result;
}
public function getAvailableContexts() {
return $this->getRuntimeContexts([]);
}
}
Classes
| Title |
Deprecated |
Summary |
| CurrentDateContext |
|
Sets the current node as a context on node routes. |