You are here

function hook_social_content_block_query_alter in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
  2. 8.6 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
  3. 8.7 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
  4. 8.8 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
  5. 10.3.x modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
  6. 10.0.x modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
  7. 10.1.x modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()

Provide a method to alter the query to get content.

Parameters

\Drupal\Core\Database\Driver\mysql\Select $query: Query to alter the results.

\Drupal\block_content\BlockContentInterface $block_content: Current block content.

1 invocation of hook_social_content_block_query_alter()
ContentBuilder::getEntities in modules/social_features/social_content_block/src/ContentBuilder.php
Function to get all the entities based on the filters.

File

modules/social_features/social_content_block/social_content_block.api.php, line 21
Hooks provided by the Social Content Block module.

Code

function hook_social_content_block_query_alter(Select $query, BlockContentInterface $block_content) {

  // Get topic type tags.
  $topic_types_list = $block_content
    ->get('field_topic_type')
    ->getValue();
  $topic_types = array_map(function ($topic_type) {
    return $topic_type['target_id'];
  }, $topic_types_list);

  // Add topic type tags.
  if (!empty($topic_types)) {
    $query
      ->innerJoin('node__field_topic_type', 'tt', 'tt.entity_id = n.nid');
    $query
      ->condition('tt.field_topic_type_target_id', $topic_types, 'IN');
  }
}