You are here

function TemplateCollection::validateTokenValues in Courier 8

Same name and namespace in other branches
  1. 2.x 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 109

Class

TemplateCollection
Defines a local template collection entity.

Namespace

Drupal\courier\Entity

Code

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)));
    }
  }
}