function _trigger_example_first_time_login in Examples for Developers 7
Trigger function for "User first time login".
This trigger is a user-type triggers, so is grouped with other user-type triggers. It needs to provide all the context that user-type triggers provide. For this example, we are going to copy the trigger.module implementation for the 'User has logged in' event.
This function will run all the actions assigned to the 'user_first_time_login' trigger.
For testing you can use an update query like this to reset a user to "never logged in":
update users set access=created where name='test1';
Parameters
string $hook: The trigger identification.
array $edit: Modifications for the account object (should be empty).
object $account: User object that has logged in.
string $category: Category of the profile.
Related topics
1 call to _trigger_example_first_time_login()
- trigger_example_user_login in trigger_example/
trigger_example.module - Implements hook_user_login().
File
- trigger_example/
trigger_example.module, line 192 - Trigger definition example module.
Code
function _trigger_example_first_time_login($hook, &$edit, $account, $category = NULL) {
// Keep objects for reuse so that changes actions make to objects can persist.
static $objects;
// Get all assigned actions for the 'user_first_time_login' trigger.
$aids = trigger_get_assigned_actions($hook);
$context = array(
'group' => 'user',
'hook' => $hook,
'form_values' => &$edit,
);
// Instead of making a call to actions_do for all triggers, doing this loop
// we provide the opportunity for actions to alter the account object, and
// the next action should have this altered account object as argument.
foreach ($aids as $aid => $info) {
$type = $info['type'];
if ($type != 'user') {
if (!isset($objects[$type])) {
$objects[$type] = _trigger_normalize_user_context($type, $account);
}
$context['user'] = $account;
actions_do($aid, $objects[$type], $context);
}
else {
actions_do($aid, $account, $context, $category);
}
}
}