class CurrentDateContext in Rules 8.3
Sets the current node as a context on node routes.
Hierarchy
- class \Drupal\rules\ContextProvider\CurrentDateContext implements ContextProviderInterface uses StringTranslationTrait
Expanded class hierarchy of CurrentDateContext
1 string reference to 'CurrentDateContext'
1 service uses CurrentDateContext
File
- src/
ContextProvider/ CurrentDateContext.php, line 14
Namespace
Drupal\rules\ContextProviderView source
class CurrentDateContext implements ContextProviderInterface {
use StringTranslationTrait;
/**
* The datetime.time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $datetime;
/**
* Constructs a new CurrentDateContext.
*
* @param \Drupal\Component\Datetime\TimeInterface $datetime
* The datetime.time service.
*/
public function __construct(TimeInterface $datetime) {
$this->datetime = $datetime;
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
return $this
->getRuntimeContexts([]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentDateContext:: |
protected | property | The datetime.time service. | |
CurrentDateContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
CurrentDateContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
CurrentDateContext:: |
public | function | Constructs a new CurrentDateContext. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |