projects
/
civicrm-core.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
6e32198
)
dev/core#1744 - Civi/Token - Simplify event naming
author
Tim Otten
<totten@civicrm.org>
Wed, 6 May 2020 02:12:53 +0000
(19:12 -0700)
committer
Tim Otten
<totten@civicrm.org>
Wed, 6 May 2020 02:51:57 +0000
(19:51 -0700)
Civi/Token/AbstractTokenSubscriber.php
patch
|
blob
|
blame
|
history
Civi/Token/Event/TokenRegisterEvent.php
patch
|
blob
|
blame
|
history
Civi/Token/Event/TokenRenderEvent.php
patch
|
blob
|
blame
|
history
Civi/Token/Event/TokenValueEvent.php
patch
|
blob
|
blame
|
history
Civi/Token/Events.php
patch
|
blob
|
blame
|
history
Civi/Token/TokenCompatSubscriber.php
patch
|
blob
|
blame
|
history
Civi/Token/TokenProcessor.php
patch
|
blob
|
blame
|
history
tests/phpunit/Civi/Token/TokenProcessorTest.php
patch
|
blob
|
blame
|
history
diff --git
a/Civi/Token/AbstractTokenSubscriber.php
b/Civi/Token/AbstractTokenSubscriber.php
index 9af4ca685442175cfed6d491a546832e9a9e328e..4f167828763e390d4ecc21e478362f01d613f66f 100644
(file)
--- a/
Civi/Token/AbstractTokenSubscriber.php
+++ b/
Civi/Token/AbstractTokenSubscriber.php
@@
-41,8
+41,8
@@
abstract class AbstractTokenSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
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',
];
}
\Civi\ActionSchedule\Events::MAILING_QUERY => 'alterActionScheduleQuery',
];
}
diff --git
a/Civi/Token/Event/TokenRegisterEvent.php
b/Civi/Token/Event/TokenRegisterEvent.php
index c7fdfa01fe7ba7228b535a27fa8ce1f7ca890434..ee867b949e895594206032a8223b045ddb7a992b 100644
(file)
--- 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
* 'label' => ts('Default Profile URL (View Mode)'),
* ));
* @endcode
+ *
+ * Event name: 'civi.token.list'
*/
class TokenRegisterEvent extends TokenEvent {
*/
class TokenRegisterEvent extends TokenEvent {
diff --git
a/Civi/Token/Event/TokenRenderEvent.php
b/Civi/Token/Event/TokenRenderEvent.php
index 3fda8442eb663aaa2bc1543f7157d613ea4a724e..5c1612e49ceb1ff22617a8164d374e1ee9d39756 100644
(file)
--- 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
*
* Class TokenRenderEvent
* @package Civi\Token\Event
*
- *
A TokenRenderEvent is fired after the TokenProcessor has rende
red
- * a message.
+ *
Perform post-processing on a rendered message. A TokenRenderEvent is fi
red
+ * a
fter 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.
* 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 {
*/
class TokenRenderEvent extends TokenEvent {
diff --git
a/Civi/Token/Event/TokenValueEvent.php
b/Civi/Token/Event/TokenValueEvent.php
index 5201ecdd6505599ac042dcabb8fbce04bb367833..c9a251ccc752ae05c24770372f7c5a1e4ce6470e 100644
(file)
--- a/
Civi/Token/Event/TokenValueEvent.php
+++ b/
Civi/Token/Event/TokenValueEvent.php
@@
-32,6
+32,7
@@
namespace Civi\Token\Event;
* }
* @encode
*
* }
* @encode
*
+ * Event name: 'civi.token.eval'
*/
class TokenValueEvent extends TokenEvent {
*/
class TokenValueEvent extends TokenEvent {
diff --git
a/Civi/Token/Events.php
b/Civi/Token/Events.php
index 7c7869ef0951b1482faba8965b423316c1e748e4..4f17c09f5441cf34c4fe664b64590e353f976499 100644
(file)
--- a/
Civi/Token/Events.php
+++ b/
Civi/Token/Events.php
@@
-4,28
+4,20
@@
namespace Civi\Token;
class Events {
/**
class Events {
/**
- * Create a list of supported tokens.
- *
* @see \Civi\Token\Event\TokenRegisterEvent
* @see \Civi\Token\Event\TokenRegisterEvent
+ * @deprecated - You may simply use the event name directly. dev/core#1744
*/
const TOKEN_REGISTER = 'civi.token.list';
/**
*/
const TOKEN_REGISTER = 'civi.token.list';
/**
- * Create a list of supported tokens.
- *
* @see \Civi\Token\Event\TokenValueEvent
* @see \Civi\Token\Event\TokenValueEvent
+ * @deprecated - You may simply use the event name directly. dev/core#1744
*/
const TOKEN_EVALUATE = 'civi.token.eval';
/**
*/
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
* @see \Civi\Token\Event\TokenRenderEvent
+ * @deprecated - You may simply use the event name directly. dev/core#1744
*/
const TOKEN_RENDER = 'civi.token.render';
*/
const TOKEN_RENDER = 'civi.token.render';
diff --git
a/Civi/Token/TokenCompatSubscriber.php
b/Civi/Token/TokenCompatSubscriber.php
index ae8a55f616652c890b199343a11f72ac64c8d5bc..c4a07af5595c81771897e0c3d0a486bd9d2d53c5 100644
(file)
--- a/
Civi/Token/TokenCompatSubscriber.php
+++ b/
Civi/Token/TokenCompatSubscriber.php
@@
-25,8
+25,8
@@
class TokenCompatSubscriber implements EventSubscriberInterface {
*/
public static function getSubscribedEvents() {
return [
*/
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 e27705300d9d9f9fa6a6a775cde796c56bed751d..0d1ff138db5038887eabfea041e2678d365e6df0 100644
(file)
--- 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']);
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;
}
}
return $this->tokens;
}
@@
-332,7
+332,7
@@
class TokenProcessor {
*/
public function evaluate() {
$event = new TokenValueEvent($this);
*/
public function evaluate() {
$event = new TokenValueEvent($this);
- $this->dispatcher->dispatch(
Events::TOKEN_EVALUATE
, $event);
+ $this->dispatcher->dispatch(
'civi.token.eval'
, $event);
return $this;
}
return $this;
}
@@
-371,7
+371,7
@@
class TokenProcessor {
$event->context = $row->context;
$event->row = $row;
$event->string = strtr($message['string'], $filteredTokens);
$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;
}
return $event->string;
}
diff --git
a/tests/phpunit/Civi/Token/TokenProcessorTest.php
b/tests/phpunit/Civi/Token/TokenProcessorTest.php
index bbef30cfe203b55461b8e626e8c597b0789de9af..f4e667a166154cd9dd10c73b2c0b8845ab7e140c 100644
(file)
--- 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->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,
$this->counts = [
'onListTokens' => 0,
'onEvalTokens' => 0,