You are here

social_content_block.api.php in Open Social 8.6

Hooks provided by the Social Content Block module.

File

modules/social_features/social_content_block/social_content_block.api.php
View source
<?php

/**
 * @file
 * Hooks provided by the Social Content Block module.
 */

/**
 * Provide a method to alter the query to get content.
 *
 * @param \Drupal\Core\Database\Driver\mysql\Select $query
 *   Query to alter the results.
 * @param \Drupal\block_content\BlockContentInterface $block_content
 *   Current block content.
 *
 * @ingroup social_content_block_api
 */
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');
  }
}

Functions

Namesort descending Description
hook_social_content_block_query_alter Provide a method to alter the query to get content.