You are here

function social_follow_taxonomy_related_entity_count in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_follow_taxonomy/social_follow_taxonomy.module \social_follow_taxonomy_related_entity_count()
  2. 10.0.x modules/social_features/social_follow_taxonomy/social_follow_taxonomy.module \social_follow_taxonomy_related_entity_count()
  3. 10.1.x modules/social_features/social_follow_taxonomy/social_follow_taxonomy.module \social_follow_taxonomy_related_entity_count()

Function for counting the number of nodes related to the term.

Parameters

\Drupal\taxonomy\TermInterface $term: Term entity.

string $field_id: Taxonomy term reference field id.

string $entity_type: Entity type ID.

Return value

int Count of related nodes.

3 calls to social_follow_taxonomy_related_entity_count()
SocialFollowTagLazyBuilder::lazyBuild in modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/SocialFollowTagLazyBuilder.php
Returns tags for lazy builder.
SocialFollowTagLazyBuilder::popupLazyBuild in modules/social_features/social_follow_taxonomy/modules/social_follow_tag/src/SocialFollowTagLazyBuilder.php
Returns render array for tag follow popup.
social_follow_landing_page_preprocess_paragraph in modules/social_features/social_follow_taxonomy/modules/social_follow_landing_page/social_follow_landing_page.module
Implements hook_preprocess_HOOK().

File

modules/social_features/social_follow_taxonomy/social_follow_taxonomy.module, line 434
Contains social_follow_taxonomy.module.

Code

function social_follow_taxonomy_related_entity_count(TermInterface $term, $field_id, $entity_type = 'node') {
  switch ($entity_type) {
    case 'node':
      $items = \Drupal::entityTypeManager()
        ->getStorage('node')
        ->getQuery()
        ->condition($field_id, $term
        ->id())
        ->addTag('node_access')
        ->addMetaData('base_table', 'node')
        ->addMetaData('op', 'view')
        ->execute();
      break;
    case 'group':
      $items = \Drupal::entityTypeManager()
        ->getStorage('group')
        ->getQuery()
        ->condition($field_id, $term
        ->id())
        ->execute();
      break;
    default:
      break;
  }
  \Drupal::moduleHandler()
    ->alter('social_follow_taxonomy_related_items', $items, $term);
  return count($items);
}