VoteActivityContext.php in Open Social 8.2
Same filename and directory in other branches
- 8.9 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8.3 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8.4 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8.5 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8.6 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8.7 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 8.8 modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 10.3.x modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 10.0.x modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 10.1.x modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
- 10.2.x modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.php
File
modules/social_features/social_like/src/Plugin/ActivityContext/VoteActivityContext.phpView source
<?php
namespace Drupal\social_like\Plugin\ActivityContext;
use Drupal\activity_creator\Plugin\ActivityContextBase;
use Drupal\votingapi\Entity\Vote;
/**
* Provides a 'VoteActivityContext' activity context.
*
* @ActivityContext(
* id = "vote_activity_context",
* label = @Translation("Vote activity context"),
* )
*/
class VoteActivityContext 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_object = $data['related_object'][0];
if ($related_object['target_type'] == 'vote') {
$vote_storage = \Drupal::entityTypeManager()
->getStorage('vote');
$vote = $vote_storage
->load($related_object['target_id']);
if ($vote instanceof Vote) {
$entity_storage = \Drupal::entityTypeManager()
->getStorage($vote
->getVotedEntityType());
/** @var \Drupal\Core\Entity\Entity $entity */
$entity = $entity_storage
->load($vote
->getVotedEntityId());
$recipients[] = [
'target_type' => 'user',
'target_id' => $entity
->getOwnerId(),
];
}
}
}
return $recipients;
}
/**
* Check if it's valid.
*/
public function isValidEntity($entity) {
if ($entity
->getEntityTypeId() === 'vote') {
return TRUE;
}
return FALSE;
}
}
Classes
Name | Description |
---|---|
VoteActivityContext | Provides a 'VoteActivityContext' activity context. |