Search code examples
solrtypo3typo3-10.x

TYPO3 10 SOLR languages and baseVariants sites config.yaml


How to write in TYPO3 the sites config.yaml for SOLR extension:

2 languages, Acceptance and Production.

I get from the webhost:

solr_host_read: solrprod02.xx.io

solr_core_read:

  • x_acc_nl
  • x_acc_en
  • x_prod_nl
  • x_prod_en

Since EXT:solr 11 it seems typoscript conditions are not allowed anymore for the connections (Legacy mode).

So how to configure for each baseVariant and each language the core?

The example in the documentation only provides an hint for the languages, not for the baseVariants https://docs.typo3.org/p/apache-solr-for-typo3/solr/11.1/en-us/Backend/ConnectionManager.html


Solution

  • A very simple way is to use the typo3conf/AdditionalConfiguration.php file and check the context there:

    <?php
    $context = (string)\TYPO3\CMS\Core\Core\Environment::getContext();
    if ($context === 'Production/Staging') {
     putenv('SOLR_ENABLED_READ=true');
     putenv('SOLR_HOST=solr');
     putenv('SOLR_PATH=/solr/');
     putenv('SOLR_PORT=8983');
     putenv('SOLR_SCHEME=http');
     putenv('SOLR_CORE_NAME_DE=core_de');
     putenv('SOLR_USER=');
     putenv('SOLR_PWD=');
    }
    

    and in your site config

    
    solr_enabled_read: true
    solr_host_read: '%env(SOLR_HOST)%'
    solr_password_read: '%env(SOLR_PWD)%'
    solr_path_read: '%env(SOLR_PATH)%'
    solr_port_read: '%env(SOLR_PORT)%'
    solr_scheme_read: '%env(SOLR_SCHEME)%'
    solr_use_write_connection: false
    solr_username_read: '%env(SOLR_USER)%'
    languages:
      -
        title: Deutsch
        enabled: true
        languageId: '0'
        base: /
        typo3Language: de
        locale: de
        iso-639-1: de
        navigationTitle: Deutsch
        hreflang: de-de
        direction: ''
        flag: at
        solr_core_read: '%env(SOLR_CORE_NAME_DE)%'