You are here

public function TopicContentBlock::query in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_block/src/Plugin/ContentBlock/TopicContentBlock.php \Drupal\social_content_block\Plugin\ContentBlock\TopicContentBlock::query()
  2. 8.8 modules/social_features/social_content_block/src/Plugin/ContentBlock/TopicContentBlock.php \Drupal\social_content_block\Plugin\ContentBlock\TopicContentBlock::query()
  3. 10.3.x modules/social_features/social_content_block/src/Plugin/ContentBlock/TopicContentBlock.php \Drupal\social_content_block\Plugin\ContentBlock\TopicContentBlock::query()
  4. 10.0.x modules/social_features/social_content_block/src/Plugin/ContentBlock/TopicContentBlock.php \Drupal\social_content_block\Plugin\ContentBlock\TopicContentBlock::query()
  5. 10.2.x modules/social_features/social_content_block/src/Plugin/ContentBlock/TopicContentBlock.php \Drupal\social_content_block\Plugin\ContentBlock\TopicContentBlock::query()

Create filtering query.

Parameters

\Drupal\Core\Database\Query\SelectInterface $query: The query.

array $fields: The fields.

Overrides ContentBlockPluginInterface::query

File

modules/social_features/social_content_block/src/Plugin/ContentBlock/TopicContentBlock.php, line 27

Class

TopicContentBlock
Provides a content block for topics.

Namespace

Drupal\social_content_block\Plugin\ContentBlock

Code

public function query(SelectInterface $query, array $fields) {
  foreach ($fields as $field_name => $entity_ids) {
    switch ($field_name) {

      // Add topic type tags.
      case 'field_topic_type':
        $query
          ->innerJoin('node__field_topic_type', 'tt', 'tt.entity_id = base_table.nid');
        $query
          ->condition('tt.field_topic_type_target_id', $entity_ids, 'IN');
        break;

      // Add group tags.
      case 'field_group':
        $query
          ->innerJoin('group_content_field_data', 'gd', 'gd.entity_id = base_table.nid');
        $query
          ->condition('gd.type', '%' . $query
          ->escapeLike('-group_node-topic'), 'LIKE');
        $query
          ->condition('gd.gid', $entity_ids, 'IN');
        break;
      case 'field_content_tags':
        $query
          ->innerJoin('node__social_tagging', 'st', 'st.entity_id = base_table.nid');
        $query
          ->condition('st.social_tagging_target_id', $entity_ids, 'IN');
        break;
    }
  }
}