You are here

function social_follow_taxonomy_theme_suggestions_activity_alter in Open Social 10.3.x

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

Implements hook_theme_suggestions_alter().

Add new activity stream message template for nodes with a term followed by the user to make it possible to override the default template.

File

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

Code

function social_follow_taxonomy_theme_suggestions_activity_alter(array &$suggestions, array $variables) {
  $activity = $variables['elements']['#activity'];

  // Get a message entity from the activity.
  $message = Message::load($activity->field_activity_message->target_id);
  $message_template = [
    'create_discussion',
    'create_event_community',
    'create_topic_community',
    'create_discussion_group',
    'create_event_group',
    'create_idea_group',
    'create_topic_group',
    'update_node_following_tag',
    'create_post_group',
    'update_post_following_tag',
  ];

  // Get the name of the template from the data of the message entity.
  if (in_array($message
    ->getTemplate()
    ->id(), $message_template)) {
    $entity_type = $activity->field_activity_entity
      ->first()->target_type;
    if (isset($activity->view) && $activity->view->current_display == 'block_stream_homepage') {
      if ($entity_type === 'node' || $entity_type === 'post') {
        $suggestions[] = 'activity__followed';
        $suggestions[] = 'activity__' . $entity_type . '__followed';
      }
    }
  }
}