class User in Audit Log 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/User.php \Drupal\audit_log\EventSubscriber\User
Processes User entity events.
@package Drupal\audit_log\EventSubscriber
Hierarchy
- class \Drupal\audit_log\EventSubscriber\User implements EventSubscriberInterface
Expanded class hierarchy of User
1 string reference to 'User'
1 service uses User
File
- src/
EventSubscriber/ User.php, line 13
Namespace
Drupal\audit_log\EventSubscriberView source
class User implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public function reactTo(AuditLogEventInterface $event) {
$entity = $event
->getEntity();
if ($entity
->getEntityTypeId() != 'user') {
return FALSE;
}
$event_type = $event
->getEventType();
$args = [
'@name' => $entity
->label(),
];
$current_state = $entity->status->value ? 'active' : 'blocked';
$original_state = NULL;
if (isset($entity->original) && $entity->original instanceof UserInterface) {
$original_state = $entity->original->status->value ? 'active' : 'blocked';
}
if ($event_type == 'insert') {
$event
->setMessage(t('@name was created.', $args))
->setPreviousState(NULL)
->setCurrentState($current_state);
return TRUE;
}
if ($event_type == 'update') {
$event
->setMessage(t('@name was updated.', $args))
->setPreviousState($original_state)
->setCurrentState($current_state);
return TRUE;
}
if ($event_type == 'delete') {
$event
->setMessage(t('@name was updated.', $args))
->setPreviousState($original_state)
->setCurrentState(NULL);
return TRUE;
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
User:: |
public | function |
Processes an event. Overrides EventSubscriberInterface:: |