Aşağıdaki kodu theme dosyanıza yapıştırarak kullanılamayan linkleri menüden kaldırılır.
function TemaAdı_preprocess_menu(&$variables) {
if ($variables['menu_name'] == 'ekonomi') {
$language = Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
foreach ($variables['items'] as $key => $item) {
if(!$variables['items'][$key] = TemaAdı_checkForMenuItemTranslation($item, $language)) {
unset($variables['items'][$key]);
}
}
}
}
function TemaAdı_checkForMenuItemTranslation($item, $language) {
$menuLinkEntity = TemaAdı_load_link_entity_by_link($item['original_link']);
if ($menuLinkEntity != NULL) {
$languages = $menuLinkEntity->getTranslationLanguages();
// Remove links which is not translated to current language.
if (!array_key_exists($language, $languages)) {
return false;
} else {
if(count($item['below']) > 0) {
foreach ($item['below'] as $subkey => $subitem) {
if(!$item['below'][$subkey] = TemaAdı_checkForMenuItemTranslation($subitem, $language)) {
unset($item['below'][$subkey]);
}
}
}
return $item;
}
}
}
function TemaAdı_load_link_entity_by_link(MenuLinkInterface $menuLinkContentPlugin) {
$entity = NULL;
if ($menuLinkContentPlugin instanceof MenuLinkContent) {
list($entity_type, $uuid) = explode(':', $menuLinkContentPlugin->getPluginId(), 2);
$entity = \Drupal::entityManager()->loadEntityByUuid($entity_type, $uuid);
}
return $entity;
}
GOSB Teknopark Hi-Tech Bina 3.Kat B3 Gebze - KOCAELİ