You are here

class ContentReportActivityContext in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  2. 8.5 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  3. 8.6 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  4. 8.7 modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  5. 10.3.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  6. 10.0.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  7. 10.1.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext
  8. 10.2.x modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php \Drupal\social_content_report\Plugin\ActivityContext\ContentReportActivityContext

Provides a 'ContentReportActivityContext' activity context.

Plugin annotation


@ActivityContext(
  id = "content_report_activity_context",
  label = @Translation("Content report activity context"),
)

Hierarchy

Expanded class hierarchy of ContentReportActivityContext

File

modules/social_features/social_content_report/src/Plugin/ActivityContext/ContentReportActivityContext.php, line 15

Namespace

Drupal\social_content_report\Plugin\ActivityContext
View source
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 = $this->entityTypeManager
      ->getStorage('user_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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActivityContextBase::$entityQuery private property The entity query.
ActivityContextBase::$entityTypeManager protected property The entity type manager.
ActivityContextBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 3
ActivityContextBase::getRecipientsFromPost public function Returns recipients from post.
ActivityContextBase::isValidEntity public function Determines if the entity is valid for this context. Overrides ActivityContextInterface::isValidEntity 8
ActivityContextBase::__construct public function ActivityContextBase constructor. Overrides PluginBase::__construct 3
ContentReportActivityContext::getRecipients public function Returns a batched list of recipients for this context. Overrides ActivityContextBase::getRecipients
ContentReportActivityContext::getRolesWithPermission protected function Returns the role with the required permission.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.