if i have a multisite setup with multi-language described here:
How to make sure that only the languages existing in the specific site will show up in the menu (right now all show up).
** props.item.state shows normal and current but not absent even if there is no Home site for the target language
how to render the link correctly with the uriSegment?
** props.item.uriSegment is giving me nothing
** also tried to add an attribut to the dimension items but its also giving me nothing
Fusion Menu
prototype(WG.BaseSite:CustomLanguageDimensionsMenu) < prototype(Neos.Fusion:Component) {
dimension = ‘language’
current = “current”
You can create a configuration in which the key at a certain point is the internal name of the site. This is a common practise for SEO or Tracking configs.
so i am using the node names to match the right config.
prototype(WG.BaseSite:CustomLanguageDimensionsMenu) < prototype(Neos.Fusion:Component) {
dimension = 'language'
rootInstanz = ${q(node).closest('[instanceof Neos.Neos:Document]').get(0)}
path = ${this.rootInstanz.nodeData.path}
# Funktion, um den Index des dritten Slashes zu finden
thirdSlashIndex = ${String.indexOf(this.path, '/', String.indexOf(this.path, '/', 1) + 1)}
# Kürzen des Pfads nach /sites/ und nach dem dritten Slash
rootNode = ${this.thirdSlashIndex != -1 ? String.substring(this.path, 7, this.thirdSlashIndex) : String.substring(this.path, 7)}
# Laden der Presets in einem sicheren Kontext mit @process
presetsBySite = ${Configuration.setting('WG.BaseSite.Dimensions.LanguagesBySite')}
# Filtern der verfügbaren Sprachdimensionen basierend auf der aktuellen Seite
@context.availablePresets = ${this.presetsBySite[this.rootNode]}
languageMenu = Neos.Neos:DimensionsMenu {
dimension = 'language'
presets = ${availablePresets}
}
renderer = afx`
<nav class="flx">
{props.languageMenu}
</nav>
`
}
I would like to have fallback links, looks like the DimensionsMenu is rendering a link only if there are matching dimensions found. Is there a way to set a fallback link to the home page of the other dimension if not?
I created a Eel helper to link the homepage of the language if no translation is available. I dont know its best practice but it works.
<?php
declare(strict_types=1);
namespace WG\BaseSite\Eel\Helper;
use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
class LanguageMenuHelper implements ProtectedContextAwareInterface
{
public function allowsCallOfMethod($methodName)
{
return true;
}
/**
* Funktion um fehlende Übersetzungen zu ermitteln und in dem Fall auf die Startseite zu verlinken
* @param array $languageMenuItems
* @return array
*/
public function getMissingTranslations($languageMenuItems)
{
foreach ($languageMenuItems as $key => $value) {
if ($value['state'] === 'absent') {
// Zielsprache
$targetLanguage = strtolower($value['label']);
// Die Zielsprache in den Link einfügen
$languageMenuItems[$key]['uri'] = '/' . $targetLanguage . '/';
}
}
return $languageMenuItems;
}
}
It works with this template.
prototype(WG.BaseSite:CustomLanguageDimensionsMenu) < prototype(Neos.Fusion:Component) {
dimension = 'language'
rootInstanz = ${q(node).closest('[instanceof Neos.Neos:Document]').get(0)}
path = ${this.rootInstanz.nodeData.path}
# Funktion, um den Index des dritten Slashes zu finden
thirdSlashIndex = ${String.indexOf(this.path, '/', String.indexOf(this.path, '/', 1) + 1)}
# Kürzen des Pfads nach /sites/ und nach dem dritten Slash
rootNode = ${this.thirdSlashIndex != -1 ? String.substring(this.path, 7, this.thirdSlashIndex) : String.substring(this.path, 7)}
# Laden der Presets in einem sicheren Kontext mit @process
presetsBySite = ${Configuration.setting('WG.BaseSite.Dimensions.LanguagesBySite')}
# Filtern der verfügbaren Sprachdimensionen basierend auf der aktuellen Seite
@context.availablePresets = ${this.presetsBySite[this.rootNode]}
# Verfügbare Übersetzungen
availableTranslations = ${this.rootInstanz.dimensions}
languageMenuItems = Neos.Neos:DimensionsMenuItems {
dimension = 'language'
presets = ${availablePresets}
}
# Menü items mit fehlenden Übersetzungen als Default
menuItems = ${WG.BaseSite.LanguageMenuHelper.getMissingTranslations(this.languageMenuItems)}
renderer = afx`
<nav class="flx">
<ul class="reset">
<Neos.Fusion:Loop items={props.menuItems} itemName="item">
<!-- Aktiver Eintrag -->
<li @if={item.state == 'current'} class="uc current">
<Neos.Neos:NodeLink node={item.node} content={item.label} />
</li>
<!-- Normale Einträge -->
<li @if={item.state == 'normal'} class="uc">
<Neos.Neos:NodeLink node={item.node} content={item.label} />
</li>
<!-- Einträge ohne direkte Übersetzung -->
<li @if={item.state == 'absent'} class="uc">
<a href={item.uri} >{item.label}</a>
</li>
</Neos.Fusion:Loop>
</ul>
</nav>
`
}