Skip to content

Commit

Permalink
ENH #16378: New Plugin Event: beforeTokenImport
Browse files Browse the repository at this point in the history
Demo plugin implementation
  • Loading branch information
gabrieljenik committed Jul 16, 2020
1 parent 9a5e59d commit 645db58
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions plugins/Demo/BeforeTokenImportDemo/BeforeTokenImportDemo.php
@@ -0,0 +1,38 @@
<?php
/**
* BeforeTokenImportDemo Plugin
*
* Demo plugin for beforeTokenImport event
*/
class BeforeTokenImportDemo extends \PluginBase
{
static protected $description = 'BeforeTokenImportDemo';
static protected $name = 'BeforeTokenImportDemo';

public function init()
{
$this->subscribe('beforeTokenImport');
}

public function beforeTokenImport()
{
$oEvent = $this->event;

// Retrieve token data from event
$tokenData = $oEvent->get('token');

// Reject tokens without Last Name
if (empty($tokenData['lastname'])) {
$oEvent->set('errorMessage', '%s records with empty Last Name ignored');
$oEvent->set('tokenSpecificErrorMessage', "Record ".$oEvent->get('recordCount')." doesn't have a last name");
$oEvent->set('importValid', false);
return;
}

// Replace Last Name by its first letter
$tokenData['lastname'] = strtoupper(substr($tokenData['lastname'], 0, 1));
$oEvent->set('token', $tokenData);
$oEvent->set('importValid', true);
}

}

0 comments on commit 645db58

Please sign in to comment.