openfed-8.x-8.5/modules/openfed_features/openfed_multilingual/openfed_multilingual.module

modules/openfed_features/openfed_multilingual/openfed_multilingual.module
<?php

/**
 * @file
 * Contains openfed_multilingual.module.
 */

use Drupal\Core\Url;

/**
 * Implements hook_language_switch_links_alter();
 *
 * This will override language switch block links, removing the link and
 * setting a "disabled" class on non-translated content.
 */
function openfed_multilingual_language_switch_links_alter(array &$links, $type, $path) {
  /** @var Drupal\node\Entity\Node $node */
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    foreach ($links as $langcode => $link) {
      if ($node && !array_key_exists($langcode, $node->getTranslationLanguages(TRUE)) || ($node->getTranslation($langcode) && !$node->getTranslation($langcode)
            ->access('view'))
      ) {
        // Set the URL to a non-link to disable the language switch for untranslated content.
        $links[$langcode]['url'] = new Url('<nolink>');
        // And do something with attributes (eg. add class).
        $links[$langcode]['attributes']['class'][] = 'disabled';
      }
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc