You are here

function social_topic_views_query_alter in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  2. 8 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  3. 8.2 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  4. 8.3 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  5. 8.5 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  6. 8.6 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  7. 8.7 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  8. 8.8 modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  9. 10.3.x modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  10. 10.0.x modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  11. 10.1.x modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()
  12. 10.2.x modules/social_features/social_topic/social_topic.module \social_topic_views_query_alter()

Implements hook_views_query_alter().

File

modules/social_features/social_topic/social_topic.module, line 143
The Social topic module.

Code

function social_topic_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view
    ->id() == 'topics' && $view
    ->getDisplay()->display['id'] == 'page_profile') {
    $account_uid = \Drupal::routeMatch()
      ->getParameter('user');
    $current_uid = \Drupal::currentUser()
      ->id();
    if ($view->exposed_raw_input['status'] == NODE_PUBLISHED || $account_uid !== $current_uid) {
      $query->where[1]['conditions'][] = [
        'field' => 'node_field_data.status',
        'value' => NODE_PUBLISHED,
        'operator' => '=',
      ];
    }
  }

  // Only show the unpublished option when you are member of the group.
  // You can't place content in a group you are not a member of anyway.
  if ($view
    ->id() == 'group_topics' && $view
    ->getDisplay()->display['id'] == 'page_group_topics') {
    $group_from_route = _social_group_get_current_group();
    $current_user = \Drupal::currentUser();
    $membership = FALSE;
    $group_membership = $group_from_route
      ->getMember($current_user);
    if ($group_membership) {
      $membership = TRUE;
    }

    // Needs 1 and NODE_PUBLISHED, because it can be TRUE ( default ) or "1"
    // (see form alter when published is selected).
    if ($view->exposed_raw_input['status'] == "1" || $view->exposed_raw_input['status'] == NODE_PUBLISHED || !$membership) {
      $query->where[1]['conditions'][] = [
        'field' => 'node_field_data_group_content_field_data.status',
        'value' => NODE_PUBLISHED,
        'operator' => '=',
      ];
    }
  }
}