You are here

function _socialbase_node_get_like_count in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  2. 8 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  3. 8.2 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  4. 8.4 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  5. 8.5 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  6. 8.6 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  7. 8.7 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()
  8. 8.8 themes/socialbase/socialbase.theme \_socialbase_node_get_like_count()

Get like count for a node.

1 call to _socialbase_node_get_like_count()
Node::preprocessElement in themes/socialbase/src/Plugin/Preprocess/Node.php
Preprocess the variables array if an element is present.

File

themes/socialbase/socialbase.theme, line 127
The primary PHP file for the Social base theme.

Code

function _socialbase_node_get_like_count($type, $id) {
  $count = 0;

  // The result function service needs entity type and entity id in order
  // to get proper results.
  if (!empty($type) && !empty($id)) {
    $manager = Drupal::service('plugin.manager.votingapi.resultfunction');
    $results = $manager
      ->getResults($type, $id);

    // Lets see if our results carry the sum of all votes.
    if (!empty($results['like']['vote_sum'])) {
      $count = $results['like']['vote_sum'];
    }
  }
  return $count;
}