Project

General

Profile

Actions

Bug #103642

open

Alternate hreflang x-default

Added by Mark Weisgerber 15 days ago. Updated 10 days ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
SEO
Start date:
2024-04-16
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.3
Tags:
x-default
Complexity:
Is Regression:
Sprint Focus:

Description

The meta tag "x-default" can currently only be changed by manually adjusting the order in the language array of the sites.yaml file. It is not possible to change the order in the backend.
The good news is that by changing the order, the correct x-default value is actually used in the frontend. In my case languageId: 2

languages:
  - languageId: 2
    enabled: true
    title: Englisch
    websiteTitle: fellow.dog
    base: 'https://www.fellow.dog/'
    locale: en_US.utf8
    navigationTitle: English
    direction: ''
    fallbackType: strict
    fallbacks: ''
    flag: en-us-gb
    deeplTargetLanguage: EN-US
  - languageId: 0
    enabled: true
    title: Deutsch
    base: 'https://www.darf-ich-mit.de/'
    locale: de_DE.utf8
    navigationTitle: Deutsch
    direction: ''
    flag: de
    websiteTitle: ''
    deeplTargetLanguage: DE

But now to the problem. Due to the change, my languageId 0 (German) is hidden in the backend when I want to edit pages. (see screenshot)
I have come across the problem with the x-default several times now, both privately and professionally, and would very much like to be able to adjust the x-default value in the sites config

The use of the EXT:cs_seo extension offers this feature, but only halfway, because the URLs for RouteEnhancers are not resolved. Therefore their feature is unfortunately unusable


Files

2024-04-16 19_04_50-Window.png (96.3 KB) 2024-04-16 19_04_50-Window.png Mark Weisgerber, 2024-04-16 18:28
Actions #1

Updated by Mark Weisgerber 14 days ago

If you need a workaround (hardcoded and not based on the LanguageID) until there is something official:

Services.yaml:

  Vendor\DarfIchMit\EventListener\ModifyHrefLangTagsEventListener:
    tags:
      - name: event.listener
        identifier: 'vendor/darf-ich-mit/modify-href-lang-tags-event-listener'
        event: 'TYPO3\CMS\Frontend\Event\ModifyHrefLangTagsEvent'

EventListener:


/**
 * Manipulates the x-default entity
 */
class ModifyHrefLangTagsEventListener
{
    /**
     * Manipulates the x-default entity
     *
     */
    public function __invoke(ModifyHrefLangTagsEvent $event): void
    {
        if(isset($event->getHrefLangs()['en-US'])){
            $event->addHrefLang('x-default', $event->getHrefLangs()['en-US']);
        }
    }
}

Actions #3

Updated by Stefan Bürk 10 days ago

  • Status changed from New to Needs Feedback

TBH I have not tested it by myself, but the siteconfiguration allows to manual set
hreflang labels for a language. And the documentation states, that it can be used
to manually define the `x-default` language.

See: https://docs.typo3.org/m/typo3/reference-coreapi/12.4/en-us/ApiOverview/SiteHandling/AddLanguages.html#sitehandling-addingLanguages

Granted, there is a note for 12.4 that this is retrieved from the locale, but as the href field is still there it may work to set it for the
whished language as `default` (or x-default`).

I could not see if you have tried that already.

Sorting the languages manually is not good, and languageId = 0 should always be the first one. It's technical the default language throughout TYPO3 and moving it away does not match the generic design and expectation - which confirms your issue after resorting it manually. I guess, all foreign language can be resorted, but leave languageId = 0 as first language per SiteConfiguration.

Actions

Also available in: Atom PDF