From 5d79840240ec76a554b9383648eae340b3528ce5 Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Mon, 3 Dec 2018 12:09:08 +0000 Subject: [PATCH] Add \Civi\Token\TokenProcessor::getContextValues() from Tim --- Civi/Token/TokenProcessor.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Civi/Token/TokenProcessor.php b/Civi/Token/TokenProcessor.php index 99a0f0f9c4..60b94b50cc 100644 --- a/Civi/Token/TokenProcessor.php +++ b/Civi/Token/TokenProcessor.php @@ -168,6 +168,29 @@ class TokenProcessor { return new TokenRowIterator($this, new \ArrayIterator($this->rowContexts)); } + /** + * Get a list of all unique values for a given context field, + * whether defined at the processor or row level. + * + * @param string $field + * Ex: 'contactId'. + * @return array + * Ex: [12, 34, 56]. + */ + public function getContextValues($field) { + $values = []; + if (isset($this->context[$field])) { + $values[] = $this->context[$field]; + } + foreach ($this->getRows() as $row) { + if (isset($row->context[$field])) { + $values[] = $row->context[$field]; + } + } + $values = array_unique($values); + return $values; + } + /** * Get the list of available tokens. * -- 2.25.1