function hook_social_content_block_query_alter in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
- 8.7 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
- 8.8 modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
- 10.3.x modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
- 10.0.x modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
- 10.1.x modules/social_features/social_content_block/social_content_block.api.php \hook_social_content_block_query_alter()
- 10.2.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::getTopics in modules/
social_features/ social_content_block/ src/ ContentBuilder.php - Function to get all the topics based on the filters.
File
- modules/
social_features/ social_content_block/ social_content_block.api.php, line 18 - Hooks provided by the Social Content Block module.
Code
function hook_social_content_block_query_alter(\Drupal\Core\Database\Driver\mysql\Select $query, \Drupal\block_content\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');
}
}