public function TemplateCollection::validateTokenValues in Courier 2.x
Same name and namespace in other branches
- 8 src/Entity/TemplateCollection.php \Drupal\courier\Entity\TemplateCollection::validateTokenValues()
Ensures tokens specified by context have values in this collection.
Throws
\Exception Throws exception if there are missing values.
Overrides TemplateCollectionInterface::validateTokenValues
File
- src/
Entity/ TemplateCollection.php, line 108
Class
- TemplateCollection
- Defines a local template collection entity.
Namespace
Drupal\courier\EntityCode
public function validateTokenValues() {
if ($this
->getContext()) {
$required_tokens = $this
->getContext()
->getTokens();
$existing_tokens = array_keys($this
->getTokenValues());
// Remove identity as it is supplied by courier.
$key = array_search('identity', $required_tokens);
unset($required_tokens[$key]);
$missing_tokens = array_diff_key($required_tokens, $existing_tokens);
if ($missing_tokens) {
throw new \Exception(sprintf('Missing tokens required by courier context: %s', implode(', ', $missing_tokens)));
}
}
}