ContentReportActivityContext.php in Open Social 8.6
Same filename and directory in other branches
- 8.9 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 8.5 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 8.7 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 8.8 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 10.3.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 10.0.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 10.1.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
- 10.2.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php
File
modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.phpView source
<?php
namespace Drupal\social_content_report\Plugin\ActivityContext;
use Drupal\activity_creator\Plugin\ActivityContextBase;
use Drupal\user\Entity\Role;
/**
* Provides a 'ContentReportActivityContext' activity context.
*
* @ActivityContext(
* id = "content_report_activity_context",
* label = @Translation("Content report activity context"),
* )
*/
class ContentReportActivityContext extends ActivityContextBase {
/**
* {@inheritdoc}
*/
public function getRecipients(array $data, $last_uid, $limit) {
$recipients = [];
$ids = $this->entityTypeManager
->getStorage('user')
->getQuery()
->condition('status', 1)
->condition('roles', $this
->getRolesWithPermission(), 'IN')
->execute();
if (!empty($ids)) {
// Create a list of recipients in the expected format.
foreach ($ids as $uid) {
$recipients[] = [
'target_type' => 'user',
'target_id' => $uid,
];
}
}
return $recipients;
}
/**
* Returns the role with the required permission.
*
* @return array
* A list of Role IDs.
*/
protected function getRolesWithPermission() {
$roles_with_perm = [];
/* @var \Drupal\user\RoleInterface[] $roles */
$roles = Role::loadMultiple();
// Check for each role which one has permission to "view inappropriate
// reports".
foreach ($roles as $role) {
if ($role
->hasPermission('view inappropriate reports')) {
$roles_with_perm[] = $role
->id();
}
}
return $roles_with_perm;
}
}
Classes
Name | Description |
---|---|
ContentReportActivityContext | Provides a 'ContentReportActivityContext' activity context. |