class Node in Audit Log 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/Node.php \Drupal\audit_log\EventSubscriber\Node
Processes node entity events.
@package Drupal\audit_log\EventSubscriber
Hierarchy
- class \Drupal\audit_log\EventSubscriber\Node implements EventSubscriberInterface
Expanded class hierarchy of Node
1 string reference to 'Node'
1 service uses Node
File
- src/
EventSubscriber/ Node.php, line 12
Namespace
Drupal\audit_log\EventSubscriberView source
class Node implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Node:: |
public | function |
Processes an event. Overrides EventSubscriberInterface:: |