From: Tim Otten Date: Wed, 6 May 2020 02:12:53 +0000 (-0700) Subject: dev/core#1744 - Civi/Token - Simplify event naming X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4c367668eca5677a72fcb6362d5e3fa014999172;hp=6e32198b6bcc4d93e62b6d033e356104da3e9b0f;p=civicrm-core.git dev/core#1744 - Civi/Token - Simplify event naming --- diff --git a/Civi/Token/AbstractTokenSubscriber.php b/Civi/Token/AbstractTokenSubscriber.php index 9af4ca6854..4f16782876 100644 --- a/Civi/Token/AbstractTokenSubscriber.php +++ b/Civi/Token/AbstractTokenSubscriber.php @@ -41,8 +41,8 @@ abstract class AbstractTokenSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ - Events::TOKEN_REGISTER => 'registerTokens', - Events::TOKEN_EVALUATE => 'evaluateTokens', + 'civi.token.list' => 'registerTokens', + 'civi.token.eval' => 'evaluateTokens', \Civi\ActionSchedule\Events::MAILING_QUERY => 'alterActionScheduleQuery', ]; } diff --git a/Civi/Token/Event/TokenRegisterEvent.php b/Civi/Token/Event/TokenRegisterEvent.php index c7fdfa01fe..ee867b949e 100644 --- a/Civi/Token/Event/TokenRegisterEvent.php +++ b/Civi/Token/Event/TokenRegisterEvent.php @@ -18,6 +18,8 @@ namespace Civi\Token\Event; * 'label' => ts('Default Profile URL (View Mode)'), * )); * @endcode + * + * Event name: 'civi.token.list' */ class TokenRegisterEvent extends TokenEvent { diff --git a/Civi/Token/Event/TokenRenderEvent.php b/Civi/Token/Event/TokenRenderEvent.php index 3fda8442eb..5c1612e49c 100644 --- a/Civi/Token/Event/TokenRenderEvent.php +++ b/Civi/Token/Event/TokenRenderEvent.php @@ -5,13 +5,15 @@ namespace Civi\Token\Event; * Class TokenRenderEvent * @package Civi\Token\Event * - * A TokenRenderEvent is fired after the TokenProcessor has rendered - * a message. + * Perform post-processing on a rendered message. A TokenRenderEvent is fired + * after the TokenProcessor has rendered a message. * - * The render event may be used for post-processing the text, but + * WARNING: The render event may be used for post-processing the text, but * it's very difficult to do substantive work in a secure, robust * way within this event. The event primarily exists to facilitate * a transition of some legacy code. + * + * Event name: 'civi.token.render' */ class TokenRenderEvent extends TokenEvent { diff --git a/Civi/Token/Event/TokenValueEvent.php b/Civi/Token/Event/TokenValueEvent.php index 5201ecdd65..c9a251ccc7 100644 --- a/Civi/Token/Event/TokenValueEvent.php +++ b/Civi/Token/Event/TokenValueEvent.php @@ -32,6 +32,7 @@ namespace Civi\Token\Event; * } * @encode * + * Event name: 'civi.token.eval' */ class TokenValueEvent extends TokenEvent { diff --git a/Civi/Token/Events.php b/Civi/Token/Events.php index 7c7869ef09..4f17c09f54 100644 --- a/Civi/Token/Events.php +++ b/Civi/Token/Events.php @@ -4,28 +4,20 @@ namespace Civi\Token; class Events { /** - * Create a list of supported tokens. - * * @see \Civi\Token\Event\TokenRegisterEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const TOKEN_REGISTER = 'civi.token.list'; /** - * Create a list of supported tokens. - * * @see \Civi\Token\Event\TokenValueEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const TOKEN_EVALUATE = 'civi.token.eval'; /** - * Perform post-processing on a rendered message. - * - * WARNING: It is difficult to develop robust, - * secure code using this stage. However, we need - * to support it during a transitional period - * while the token logic is reorganized. - * * @see \Civi\Token\Event\TokenRenderEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const TOKEN_RENDER = 'civi.token.render'; diff --git a/Civi/Token/TokenCompatSubscriber.php b/Civi/Token/TokenCompatSubscriber.php index ae8a55f616..c4a07af559 100644 --- a/Civi/Token/TokenCompatSubscriber.php +++ b/Civi/Token/TokenCompatSubscriber.php @@ -25,8 +25,8 @@ class TokenCompatSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::TOKEN_EVALUATE => 'onEvaluate', - Events::TOKEN_RENDER => 'onRender', + 'civi.token.eval' => 'onEvaluate', + 'civi.token.render' => 'onRender', ]; } diff --git a/Civi/Token/TokenProcessor.php b/Civi/Token/TokenProcessor.php index e27705300d..0d1ff138db 100644 --- a/Civi/Token/TokenProcessor.php +++ b/Civi/Token/TokenProcessor.php @@ -306,7 +306,7 @@ class TokenProcessor { if ($this->tokens === NULL) { $this->tokens = []; $event = new TokenRegisterEvent($this, ['entity' => 'undefined']); - $this->dispatcher->dispatch(Events::TOKEN_REGISTER, $event); + $this->dispatcher->dispatch('civi.token.list', $event); } return $this->tokens; } @@ -332,7 +332,7 @@ class TokenProcessor { */ public function evaluate() { $event = new TokenValueEvent($this); - $this->dispatcher->dispatch(Events::TOKEN_EVALUATE, $event); + $this->dispatcher->dispatch('civi.token.eval', $event); return $this; } @@ -371,7 +371,7 @@ class TokenProcessor { $event->context = $row->context; $event->row = $row; $event->string = strtr($message['string'], $filteredTokens); - $this->dispatcher->dispatch(Events::TOKEN_RENDER, $event); + $this->dispatcher->dispatch('civi.token.render', $event); return $event->string; } diff --git a/tests/phpunit/Civi/Token/TokenProcessorTest.php b/tests/phpunit/Civi/Token/TokenProcessorTest.php index bbef30cfe2..f4e667a166 100644 --- a/tests/phpunit/Civi/Token/TokenProcessorTest.php +++ b/tests/phpunit/Civi/Token/TokenProcessorTest.php @@ -22,8 +22,8 @@ class TokenProcessorTest extends \CiviUnitTestCase { $this->useTransaction(TRUE); parent::setUp(); $this->dispatcher = new EventDispatcher(); - $this->dispatcher->addListener(Events::TOKEN_REGISTER, [$this, 'onListTokens']); - $this->dispatcher->addListener(Events::TOKEN_EVALUATE, [$this, 'onEvalTokens']); + $this->dispatcher->addListener('civi.token.list', [$this, 'onListTokens']); + $this->dispatcher->addListener('civi.token.eval', [$this, 'onEvalTokens']); $this->counts = [ 'onListTokens' => 0, 'onEvalTokens' => 0,