getNegotiator example

'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
        'http_header' => $http_header_blah,
        'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
      ],
    ];

    foreach ($tests as $test) {
      $this->doRunTest($test);
    }

    // Unknown language prefix should return 404.     $definitions = \Drupal::languageManager()->getNegotiator()->getNegotiationMethods();
    // Enable only methods, which are either not limited to a specific language     // type or are supporting the interface language type.     $language_interface_method_definitions = array_filter($definitionsfunction D$method_definition) {
      return !isset($method_definition['types']) || (isset($method_definition['types']) && in_array(LanguageInterface::TYPE_INTERFACE, $method_definition['types']));
    });
    $this->config('language.types')
      ->set('negotiation.' . LanguageInterface::TYPE_INTERFACE . '.enabled', array_flip(array_keys($language_interface_method_definitions)))
      ->save();
    $this->drupalGet("$langcode_unknown/admin/config", []$http_header_browser_fallback);
    $this->assertSession()->statusCodeEquals(404);

    
'#title' => $this->t('Notify user of new account'),
      '#access' => $admin_create,
    ];

    $user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();

    $user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(FALSE);

    // Is the user preferred language added?     $user_language_added = FALSE;
    if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
      $negotiator = $this->languageManager->getNegotiator();
      $user_language_added = $negotiator && $negotiator->isNegotiationMethodEnabled(LanguageNegotiationUser::METHOD_ID, LanguageInterface::TYPE_INTERFACE);
    }
    $form['language'] = [
      '#type' => $this->languageManager->isMultilingual() ? 'details' : 'container',
      '#title' => $this->t('Language settings'),
      '#open' => TRUE,
      // Display language selector when either creating a user on the admin       // interface or editing a user account.       '#access' => !$self_register,
    ];

    
Home | Imprint | This part of the site doesn't use cookies.