I am developing an extension for civicrm 4.7. This extension includes several tokens. One of the tokens I want to include is a token for the activity assignee to be used in scheduled reminders.
In Civi 4.7 the hook system is expanded with Symfony Event Dispatchers and it looks like the token evaluate event will give me the oppurtunity to do exactly what is needed.
However I am confused in how to register an event listener. I have implemented the hook_civicrm_container but my events are never called.
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
function tokens_civicrm_container(containerBuilder $container) {
$container->addResource(new FileResource(__FILE__));
$container->findDefinition('dispatcher')->addMethodCall('addListener',
array(\Civi\Token\Events::TOKEN_EVALUATE, 'tokens_evaluate_tokens')
);
}
function tokens_evaluate_tokens(\Civi\Token\Event\TokenValueEvent $e) {
foreach ($e->getRows() as $row) {
/** @var TokenRow $row */
$row->format('text/html');
$row->tokens('profile', 'viewUrl', 'http://example.com/profile/' . $row->context['contact_id']);
$row->tokens('profile', 'viewLink', ts("<a href='%1'>Open Profile</a>", array(
1 => $row->tokens['profile']['viewUrl'],
)));
}
}
What is wrong with my code?