public function ActivityLoggerFactory::createMessages in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.2 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.3 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.4 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.5 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.6 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.7 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 8.8 modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 10.3.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 10.0.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 10.1.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
- 10.2.x modules/custom/activity_logger/src/Service/ActivityLoggerFactory.php \Drupal\activity_logger\Service\ActivityLoggerFactory::createMessages()
Create message entities.
Parameters
\Drupal\Core\Entity\Entity $entity: Entity object to create a message for.
string $action: Action string. Defaults to 'create'.
File
- modules/
custom/ activity_logger/ src/ Service/ ActivityLoggerFactory.php, line 24
Class
- ActivityLoggerFactory
- Class ActivityLoggerFactory.
Namespace
Drupal\activity_logger\ServiceCode
public function createMessages(Entity $entity, $action) {
// Get all messages that are responsible for creating items.
$message_types = $this
->getMessageTypes($action, $entity);
// Loop through those message types and create messages.
foreach ($message_types as $message_type => $message_values) {
// Create the ones applicable for this bundle.
// Determine destinations.
$destinations = [];
if (!empty($message_values['destinations']) && is_array($message_values['destinations'])) {
foreach ($message_values['destinations'] as $destination) {
$destinations[] = [
'value' => $destination,
];
}
}
$mt_context = $message_values['context'];
// Set the values.
$new_message['template'] = $message_type;
$new_message['created'] = $entity
->getCreatedTime();
$new_message['uid'] = $entity
->getOwner()
->id();
$additional_fields = [
[
'name' => 'field_message_context',
'type' => 'list_string',
],
[
'name' => 'field_message_destination',
'type' => 'list_string',
],
[
'name' => 'field_message_related_object',
'type' => 'dynamic_entity_reference',
],
];
$this
->createFieldInstances($message_type, $additional_fields);
$new_message['field_message_context'] = $mt_context;
$new_message['field_message_destination'] = $destinations;
$new_message['field_message_related_object'] = [
'target_type' => $entity
->getEntityTypeId(),
'target_id' => $entity
->id(),
];
// Create the message.
$message = Message::create($new_message);
$message
->save();
}
}