PlatformActivityContext.php in Open Social 10.0.x
Same filename and directory in other branches
- 8.9 modules/custom/activity_basics/src/Plugin/ActivityContext/PlatformActivityContext.php
- 8.8 modules/custom/activity_basics/src/Plugin/ActivityContext/PlatformActivityContext.php
- 10.3.x modules/custom/activity_basics/src/Plugin/ActivityContext/PlatformActivityContext.php
- 10.1.x modules/custom/activity_basics/src/Plugin/ActivityContext/PlatformActivityContext.php
- 10.2.x modules/custom/activity_basics/src/Plugin/ActivityContext/PlatformActivityContext.php
File
modules/custom/activity_basics/src/Plugin/ActivityContext/PlatformActivityContext.phpView source
<?php
namespace Drupal\activity_basics\Plugin\ActivityContext;
use Drupal\activity_creator\Plugin\ActivityContextBase;
/**
* Provides a 'OwnerActivityContext' activity context.
*
* @ActivityContext(
* id = "platform_activity_context",
* label = @Translation("Platform activity context"),
* )
*/
class PlatformActivityContext extends ActivityContextBase {
/**
* {@inheritdoc}
*/
public function getRecipients(array $data, $last_uid, $limit) {
$recipients = [];
// We only know the context if there is a related object.
if (isset($data['related_object']) && !empty($data['related_object'])) {
$related_entity = $this->activityFactory
->getActivityRelatedEntity($data);
// Load the related entity.
$entity_storage = $this->entityTypeManager
->getStorage($related_entity['target_type']);
$entity = $entity_storage
->load($related_entity['target_id']);
// When nothing found return the empty recipients array. Basically means
// there is no activity sent.
if ($entity === NULL) {
return $recipients;
}
// Add the owner of the related entity as a recipient.
// No owner found set user 1.
$recipients[] = [
'target_type' => 'user',
'target_id' => $entity
->getOwnerId() ?? 1,
];
}
return $recipients;
}
}
Classes
Name | Description |
---|---|
PlatformActivityContext | Provides a 'OwnerActivityContext' activity context. |