public function Node::reactTo in Audit Log 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/Node.php \Drupal\audit_log\EventSubscriber\Node::reactTo()
Processes an event.
Parameters
\Drupal\audit_log\AuditLogEventInterface $event: The audit event.
Return value
bool TRUE if the event subscriber handled the event.
Overrides EventSubscriberInterface::reactTo
File
- src/
EventSubscriber/ Node.php, line 17
Class
- Node
- Processes node entity events.
Namespace
Drupal\audit_log\EventSubscriberCode
public function reactTo(AuditLogEventInterface $event) {
$entity = $event
->getEntity();
if ($entity
->getEntityTypeId() != 'node') {
return FALSE;
}
$event_type = $event
->getEventType();
/** @var \Drupal\node\NodeInterface $entity */
$current_state = $entity
->isPublished() ? 'published' : 'unpublished';
$previous_state = '';
if (isset($entity->original)) {
$previous_state = $entity->original
->isPublished() ? 'published' : 'unpublished';
}
$args = [
'@title' => $entity
->getTitle(),
];
if ($event_type == 'insert') {
$event
->setMessage('@name was created.')
->setMessagePlaceholders([
'@name' => $entity
->label(),
])
->setPreviousState(NULL)
->setCurrentState($current_state);
return TRUE;
}
if ($event_type == 'update') {
$event
->setMessage('@name was updated.')
->setMessagePlaceholders([
'@name' => $entity
->label(),
])
->setPreviousState($previous_state)
->setCurrentState($current_state);
return TRUE;
}
if ($event_type == 'delete') {
$event
->setMessage('@name was deleted.')
->setMessagePlaceholders([
'@name' => $entity
->label(),
])
->setPreviousState($previous_state)
->setCurrentState(NULL);
return TRUE;
}
return FALSE;
}