Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH #16378: New Plugin Event: beforeTokenImport
Demo plugin implementation
- Loading branch information
1 parent
9a5e59d
commit 645db58
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
plugins/Demo/BeforeTokenImportDemo/BeforeTokenImportDemo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |