You are here

class CurrentDateContext in Rules 8.3

Sets the current node as a context on node routes.

Hierarchy

Expanded class hierarchy of CurrentDateContext

1 string reference to 'CurrentDateContext'
rules.services.yml in ./rules.services.yml
rules.services.yml
1 service uses CurrentDateContext
rules.current_date_context in ./rules.services.yml
Drupal\rules\ContextProvider\CurrentDateContext

File

src/ContextProvider/CurrentDateContext.php, line 14

Namespace

Drupal\rules\ContextProvider
View 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

Namesort descending Modifiers Type Description Overrides
CurrentDateContext::$datetime protected property The datetime.time service.
CurrentDateContext::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
CurrentDateContext::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts
CurrentDateContext::__construct public function Constructs a new CurrentDateContext.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.