class ScheduledTransitionsTokenReplacements in Scheduled Transitions 2.x
Represents strings used as replacement variables in translation or logger.
Hierarchy
- class \Drupal\scheduled_transitions\ScheduledTransitionsTokenReplacements uses StringTranslationTrait
Expanded class hierarchy of ScheduledTransitionsTokenReplacements
1 file declares its use of ScheduledTransitionsTokenReplacements
- ScheduledTransitionsTokenTest.php in tests/
src/ Kernel/ ScheduledTransitionsTokenTest.php
File
- src/
ScheduledTransitionsTokenReplacements.php, line 16
Namespace
Drupal\scheduled_transitionsView source
class ScheduledTransitionsTokenReplacements {
use StringTranslationTrait;
/**
* A scheduled transition entity.
*
* @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface
*/
protected $scheduledTransition;
/**
* A new default revision.
*
* @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface
*/
protected $newRevision;
/**
* The latest current revision.
*
* @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface
*/
protected $latest;
/**
* Moderation information service.
*
* @var \Drupal\content_moderation\ModerationInformationInterface|null
*/
protected $moderationInformation;
/**
* An array of replacements.
*
* @var array|null
*/
protected $cachedReplacements;
/**
* ScheduledTransitionsTokens constructor.
*
* @param \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition
* A scheduled transition entity.
* @param \Drupal\Core\Entity\EntityInterface $newRevision
* A new default revision.
* @param \Drupal\Core\Entity\EntityInterface $latest
* The latest current revision.
*/
public function __construct(ScheduledTransitionInterface $scheduledTransition, EntityInterface $newRevision, EntityInterface $latest) {
$this->scheduledTransition = $scheduledTransition;
$this->newRevision = $newRevision;
$this->latest = $latest;
}
/**
* Get variables for translation or replacement.
*
* @return array
* An array of strings keyed by replacement key.
*/
public function getReplacements() {
if (isset($this->cachedReplacements)) {
return $this->cachedReplacements;
}
$entityRevisionId = $this->newRevision
->getRevisionId();
// getWorkflowForEntity only supports Content Entities, this can be removed
// if Scheduled Transitions supports non CM workflows in the future.
if ($this->latest instanceof ContentEntityInterface) {
$workflow = $this
->moderationInformation()
->getWorkflowForEntity($this->latest);
$workflowPlugin = $workflow
->getTypePlugin();
$states = $workflowPlugin
->getStates();
}
$originalNewRevisionState = $states[$this->newRevision->moderation_state->value ?? ''] ?? NULL;
$originalLatestState = $states[$this->latest->moderation_state->value ?? ''] ?? NULL;
$newState = $states[$this->scheduledTransition
->getState()] ?? NULL;
return $this->cachedReplacements = [
'from-revision-id' => $entityRevisionId,
'from-state' => $originalNewRevisionState ? $originalNewRevisionState
->label() : $this
->t('- Unknown state -'),
'to-state' => $newState ? $newState
->label() : $this
->t('- Unknown state -'),
'latest-revision-id' => $this->latest
->getRevisionId(),
'latest-state' => $originalLatestState ? $originalLatestState
->label() : $this
->t('- Unknown state -'),
];
}
/**
* Moderation information service.
*
* @return \Drupal\content_moderation\ModerationInformationInterface
* Moderation information service.
*/
protected function moderationInformation() : ModerationInformationInterface {
return $this->moderationInformation ?? \Drupal::service('content_moderation.moderation_information');
}
/**
* Sets moderation information service.
*
* @param \Drupal\content_moderation\ModerationInformationInterface $moderationInformation
* Moderation information service.
*/
public function setModerationInformation(ModerationInformationInterface $moderationInformation) : void {
$this->moderationInformation = $moderationInformation;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ScheduledTransitionsTokenReplacements:: |
protected | property | An array of replacements. | |
ScheduledTransitionsTokenReplacements:: |
protected | property | The latest current revision. | |
ScheduledTransitionsTokenReplacements:: |
protected | property | Moderation information service. | |
ScheduledTransitionsTokenReplacements:: |
protected | property | A new default revision. | |
ScheduledTransitionsTokenReplacements:: |
protected | property | A scheduled transition entity. | |
ScheduledTransitionsTokenReplacements:: |
public | function | Get variables for translation or replacement. | |
ScheduledTransitionsTokenReplacements:: |
protected | function | Moderation information service. | |
ScheduledTransitionsTokenReplacements:: |
public | function | Sets moderation information service. | |
ScheduledTransitionsTokenReplacements:: |
public | function | ScheduledTransitionsTokens constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |