You are here

public function PostVisibilityAccess::query in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  2. 8.2 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  3. 8.3 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  4. 8.4 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  5. 8.5 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  6. 8.6 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  7. 8.7 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  8. 8.8 modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  9. 10.3.x modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  10. 10.0.x modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  11. 10.1.x modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()
  12. 10.2.x modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php \Drupal\social_post\Plugin\views\filter\PostVisibilityAccess::query()

Currently use similar access as for the entity.

Probably want to extend this to entity access based on the node grant system when this is implemented. See https://www.drupal.org/node/777578

Overrides FilterPluginBase::query

File

modules/social_features/social_post/src/Plugin/views/filter/PostVisibilityAccess.php, line 43

Class

PostVisibilityAccess
Filters post based on visibility settings.

Namespace

Drupal\social_post\Plugin\views\filter

Code

public function query() {
  $account = $this->view
    ->getUser();
  $this->query
    ->addTable('post__field_visibility');
  $and_condition = db_and();
  $should_add_where_clause = FALSE;
  if (!$account
    ->hasPermission('view public posts')) {
    $and_condition
      ->condition('post__field_visibility.field_visibility_value', '1', '!=');
    $should_add_where_clause = TRUE;
  }
  if (!$account
    ->hasPermission('view community posts')) {
    $and_condition
      ->condition('post__field_visibility.field_visibility_value', '2', '!=');
    $should_add_where_clause = TRUE;
  }
  if ($should_add_where_clause) {
    $this->query
      ->addWhere('visibility', $and_condition);
  }
}