You are here

function social_core_preprocess_block in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  2. 8 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  3. 8.2 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  4. 8.3 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  5. 8.4 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  6. 8.5 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  7. 8.6 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  8. 8.7 modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  9. 10.3.x modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  10. 10.0.x modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  11. 10.1.x modules/social_features/social_core/social_core.module \social_core_preprocess_block()
  12. 10.2.x modules/social_features/social_core/social_core.module \social_core_preprocess_block()

Implements hook_preprocess_block().

File

modules/social_features/social_core/social_core.module, line 181
The Social core module.

Code

function social_core_preprocess_block(&$variables) {

  /** @var \Drupal\user\Entity\User $account */
  $account = \Drupal::routeMatch()
    ->getParameter('user');

  /** @var \Drupal\group\Entity\Group $group */
  $group = \Drupal::routeMatch()
    ->getParameter('group');
  if (is_numeric($account)) {
    $account = User::load($account);
  }
  if (is_numeric($group)) {
    $group = Group::load($group);
  }
  if (!empty($variables['elements']['content']['#view'])) {
    $view = $variables['elements']['content']['#view'];
    if (!empty($view
      ->getDisplay())) {
      $link = $view
        ->getDisplay();
      if (!empty($link
        ->useMoreText())) {
        $more_link = $link
          ->useMoreText();
      }
    }
  }

  // Add variables to sidebar blocks.
  switch ($variables['elements']['#derivative_plugin_id']) {
    case 'upcoming_events-block_my_upcoming_events':
      $variables['view_all_path'] = Url::fromRoute('view.events.events_overview', [
        'user' => \Drupal::currentUser()
          ->id(),
      ]);
      $variables['button_text'] = $more_link;
      $link
        ->setOption('use_more', FALSE);
      break;
    case 'upcoming_events-block_community_events':
      $variables['subtitle'] = t('in the community');
      $variables['view_all_path'] = Url::fromRoute('view.upcoming_events.page_community_events');
      if (isset($variables['label']['#markup'])) {
        $label = $variables['label']['#markup'];
      }
      else {
        $label = t('events');
      }
      $variables['button_text'] = t('All @label', [
        '@label' => $label,
      ]);
      break;
    case 'latest_topics-block_latest_topics':
      $variables['subtitle'] = t('in the community');
      $variables['view_all_path'] = Url::fromRoute('view.latest_topics.page_latest_topics');
      $variables['button_text'] = $more_link;
      $link
        ->setOption('use_more', FALSE);
      break;
    case 'newest_groups-block_newest_groups':
      $variables['subtitle'] = t('in the community');
      $variables['view_all_path'] = Url::fromRoute('view.newest_groups.page_all_groups');
      $variables['button_text'] = $more_link;
      $link
        ->setOption('use_more', FALSE);
      break;
    case 'newest_users-block_newest_users':
      $variables['subtitle'] = t('in the community');
      $variables['view_all_path'] = Url::fromRoute('view.newest_users.page_newest_users');
      $variables['button_text'] = $more_link;
      $link
        ->setOption('use_more', FALSE);
      break;
    case 'events-block_events_on_profile':
      if ($account instanceof UserInterface) {
        $variables['subtitle'] = t('for this user');
        $variables['view_all_path'] = Url::fromRoute('view.events.events_overview', [
          'user' => $account
            ->id(),
        ]);
        $variables['button_text'] = t('All @label', [
          '@label' => $variables['label']['#markup'],
        ]);
      }
      break;
    case 'topics-block_user_topics':
      if ($account instanceof UserInterface) {
        $variables['subtitle'] = t('for this user');
        $variables['view_all_path'] = Url::fromRoute('view.topics.page_profile', [
          'user' => $account
            ->id(),
        ]);
        $variables['button_text'] = $more_link;
        $link
          ->setOption('use_more', FALSE);
      }
      break;
    case 'groups-block_user_groups':
      if ($account instanceof UserInterface) {
        $variables['subtitle'] = t('for this user');
        $variables['view_all_path'] = Url::fromRoute('view.groups.page_user_groups', [
          'user' => $account
            ->id(),
        ]);
        $variables['button_text'] = $more_link;
        $link
          ->setOption('use_more', FALSE);
      }
      break;
    case 'group_members-block_newest_members':
      $variables['subtitle'] = t('in the group');
      $variables['view_all_path'] = Url::fromRoute('view.group_members.page_group_members', [
        'group' => $group
          ->id(),
      ]);
      $variables['button_text'] = $more_link;
      $link
        ->setOption('use_more', FALSE);
      break;
    case 'upcoming_events-upcoming_events_group':
      $variables['subtitle'] = t('in the group');
      $variables['view_all_path'] = Url::fromRoute('view.group_events.page_group_events', [
        'group' => $group
          ->id(),
      ]);
      $variables['button_text'] = t('All @label', [
        '@label' => $variables['label']['#markup'],
      ]);
      break;
    case 'latest_topics-group_topics_block':
      $variables['subtitle'] = t('in the group');
      $variables['view_all_path'] = Url::fromRoute('view.group_topics.page_group_topics', [
        'group' => $group
          ->id(),
      ]);
      $variables['button_text'] = $more_link;
      $link
        ->setOption('use_more', FALSE);
      break;
  }
}