You are here

function social_follow_tag_preprocess_social_tagging_nosplit in Open Social 10.3.x

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

Extends variables for social_tagging_nosplit template.

Implements hook_preprocess_HOOK().

File

modules/social_features/social_follow_taxonomy/modules/social_follow_tag/social_follow_tag.module, line 132
Contains social_follow_tag.module.

Code

function social_follow_tag_preprocess_social_tagging_nosplit(&$variables) {
  if (!isset($variables['tags'])) {
    return;
  }

  // Get entity type for rendered tags.
  $entity_type = $variables['entity_type'];

  /** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
  $term_storage = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term');
  foreach ($variables['tags'] as $tag_name => $tag_info) {

    // Get term id from the transmitted url string.
    $term_id_from_string = explode('/search/content?tag%5B%5D=', $tag_info);
    if ($entity_type === 'group') {
      $term_id_from_string = explode('/search/groups?tag%5B%5D=', $tag_info);
    }
    if (isset($term_id_from_string[1])) {
      $current_term = $term_storage
        ->load($term_id_from_string[1]);
    }

    // Must be a valid Term.
    if (!isset($current_term) || !$current_term instanceof TermInterface) {
      continue;
    }

    // Adding additional data to the term variable to extend the template.
    $variables['tags'][$tag_name] = [
      'popup' => [
        '#create_placeholder' => TRUE,
        '#lazy_builder' => [
          'social_follow_tag.lazy_builder:popupLazyBuild',
          [
            $tag_info,
            $current_term
              ->id(),
            'social_tagging',
            $entity_type,
          ],
        ],
      ],
      'name' => $tag_name,
      'follow' => social_follow_taxonomy_term_followed($current_term),
    ];
    $tag_id = $current_term
      ->id();
    $variables['#cache']['tags'][] = "follow_tag_{$entity_type}:{$tag_id}";
  }
  $variables['#cache']['tags'][] = 'flagging_list';
}