You are here

class GroupActivityContext in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  2. 8 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  3. 8.2 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  4. 8.3 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  5. 8.4 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  6. 8.5 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  7. 8.6 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  8. 8.7 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  9. 8.8 modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  10. 10.3.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  11. 10.1.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext
  12. 10.2.x modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php \Drupal\activity_basics\Plugin\ActivityContext\GroupActivityContext

Provides a 'GroupActivityContext' activity context.

Plugin annotation


@ActivityContext(
  id = "group_activity_context",
  label = @Translation("Group activity context"),
)

Hierarchy

Expanded class hierarchy of GroupActivityContext

File

modules/custom/activity_basics/src/Plugin/ActivityContext/GroupActivityContext.php, line 22

Namespace

Drupal\activity_basics\Plugin\ActivityContext
View source
class GroupActivityContext extends ActivityContextBase {

  /**
   * The group helper service.
   *
   * @var \Drupal\social_group\SocialGroupHelperService
   */
  protected $grouphelperService;

  /**
   * ActivityContextBase constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\Query\Sql\QueryFactory $entity_query
   *   The entity query.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\activity_creator\ActivityFactory $activity_factory
   *   The activity factory service.
   * @param \Drupal\social_group\SocialGroupHelperService $grouphelper_service
   *   The group helper service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryFactory $entity_query, EntityTypeManagerInterface $entity_type_manager, ActivityFactory $activity_factory, SocialGroupHelperService $grouphelper_service) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_query, $entity_type_manager, $activity_factory);
    $this->grouphelperService = $grouphelper_service;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity.query.sql'), $container
      ->get('entity_type.manager'), $container
      ->get('activity_creator.activity_factory'), $container
      ->get('social_group.helper_service'));
  }

  /**
   * {@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'])) {
      $referenced_entity = $data['related_object']['0'];
      if ($gid = $this->grouphelperService
        ->getGroupFromEntity($referenced_entity, FALSE)) {
        $recipients[] = [
          'target_type' => 'group',
          'target_id' => $gid,
        ];
      }
    }
    return $recipients;
  }

  /**
   * {@inheritdoc}
   */
  public function isValidEntity(EntityInterface $entity) {

    // Special cases for comments.
    if ($entity
      ->getEntityTypeId() === 'comment') {

      // Returns the entity to which the comment is attached.
      $entity = $entity
        ->getCommentedEntity();
    }
    if (!isset($entity)) {
      return FALSE;
    }

    // Check if it's placed in a group (regardless off content type).
    if (GroupContent::loadByEntity($entity)) {
      return TRUE;
    }
    if ($entity
      ->getEntityTypeId() === 'post') {
      if (!$entity->field_recipient_group
        ->isEmpty()) {
        return TRUE;
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActivityContextBase::$activityFactory protected property The activity factory service.
ActivityContextBase::$entityQuery private property The entity query.
ActivityContextBase::$entityTypeManager protected property The entity type manager.
ActivityContextBase::getRecipientsFromPost public function Returns recipients from post.
GroupActivityContext::$grouphelperService protected property The group helper service.
GroupActivityContext::create public static function Creates an instance of the plugin. Overrides ActivityContextBase::create
GroupActivityContext::getRecipients public function Returns a batched list of recipients for this context. Overrides ActivityContextBase::getRecipients
GroupActivityContext::isValidEntity public function Determines if the entity is valid for this context. Overrides ActivityContextBase::isValidEntity
GroupActivityContext::__construct public function ActivityContextBase constructor. Overrides ActivityContextBase::__construct
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 2
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.