You are here

social_language.module in Open Social 10.0.x

File

modules/custom/social_language/social_language.module
View source
<?php

/**
 * @file
 * Contains social_language.module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 * Implements hook_language_switch_links_alter().
 */
function social_language_language_switch_links_alter(array &$links, $type, Url $url) {
  $currentLangcode = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  foreach ($links as $langcode => &$link) {
    $link['attributes']['title'] = $link['title'];
    $link['title'] .= " ({$langcode})";
    $link['attributes']['class'][] = $langcode === $currentLangcode ? 'active' : NULL;
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function social_language_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  /** @var \Drupal\Core\Config\ImmutableConfig $language_types */
  $language_negotiations = \Drupal::configFactory()
    ->get('language.types')
    ->get('negotiation');

  // Show the preferred language field only when the user language negotiation
  // is set to user and we have at least two languages.
  if (isset($language_negotiations['language_interface']['enabled']['language-user']) && count(\Drupal::languageManager()
    ->getLanguages()) > 1) {
    $form['language']['#title'] = NULL;
    $form['language']['preferred_langcode']['#title'] = t('Interface language');
    $form['language']['preferred_langcode']['#description'] = t('Select the language you want to use this site in.');
    $form['language']['#attributes']['class'][] = 'form-horizontal';
  }
  else {
    $form['language']['#access'] = FALSE;
  }
}

/**
 * Implements hook_default_route_group_tabs_alter().
 */
function social_language_social_group_default_route_tabs_alter(&$tabs) {

  // Unset some tabs created by group.
  unset($tabs['content_translation.local_tasks:entity.group.content_translation_overview']);
}