You are here

class TestLanguageNegotiator in Language Selection Page 8.2

Test language negotiator.

Plugin annotation


@LanguageNegotiation(
    id=\Drupal\language_selection_page_test\Plugin\LanguageNegotiation\TestLanguageNegotiator::METHOD_ID,
    types={
        \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE,
        \Drupal\Core\Language\LanguageInterface::TYPE_CONTENT,
        \Drupal\Core\Language\LanguageInterface::TYPE_URL
    },
    weight=-20,
    name=@Translation("Test Language Negotiator"),
    description=@Translation("Test Language Negotiator"),
)

Hierarchy

Expanded class hierarchy of TestLanguageNegotiator

File

tests/modules/src/Plugin/LanguageNegotiation/TestLanguageNegotiator.php, line 26

Namespace

Drupal\language_selection_page_test\Plugin\LanguageNegotiation
View source
class TestLanguageNegotiator extends LanguageNegotiationUrl {

  /**
   * The language negotiation method id.
   */
  public const METHOD_ID = 'language-selection-page-test-negotiator';

  /**
   * {@inheritdoc}
   */
  public function getLangcode(?Request $request = NULL) {
    $request_path = urldecode(trim($request
      ->getPathInfo(), '/'));
    if (strpos($request_path, '-fake') !== FALSE) {
      return 'fake';
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function processInbound($path, Request $request) {
    return str_replace('-fake', '', $path);
  }

  /**
   * {@inheritdoc}
   */
  public function processOutbound($path, &$options = [], ?Request $request = NULL, ?BubbleableMetadata $bubbleable_metadata = NULL) {
    return $path . '-fake';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageNegotiationMethodBase::$config protected property The configuration factory.
LanguageNegotiationMethodBase::$currentUser protected property The current active user.
LanguageNegotiationMethodBase::$languageManager protected property The language manager.
LanguageNegotiationMethodBase::persist public function Notifies the plugin that the language code it returned has been accepted. Overrides LanguageNegotiationMethodInterface::persist 1
LanguageNegotiationMethodBase::setConfig public function Injects the configuration factory. Overrides LanguageNegotiationMethodInterface::setConfig
LanguageNegotiationMethodBase::setCurrentUser public function Injects the current user. Overrides LanguageNegotiationMethodInterface::setCurrentUser
LanguageNegotiationMethodBase::setLanguageManager public function Injects the language manager. Overrides LanguageNegotiationMethodInterface::setLanguageManager
LanguageNegotiationUrl::CONFIG_DOMAIN constant URL language negotiation: use the domain as URL language indicator.
LanguageNegotiationUrl::CONFIG_PATH_PREFIX constant URL language negotiation: use the path prefix as URL language indicator.
LanguageNegotiationUrl::getLanguageSwitchLinks public function Returns language switch links. Overrides LanguageSwitcherInterface::getLanguageSwitchLinks
TestLanguageNegotiator::getLangcode public function Performs language negotiation. Overrides LanguageNegotiationUrl::getLangcode
TestLanguageNegotiator::METHOD_ID public constant The language negotiation method id. Overrides LanguageNegotiationUrl::METHOD_ID
TestLanguageNegotiator::processInbound public function Processes the inbound path. Overrides LanguageNegotiationUrl::processInbound
TestLanguageNegotiator::processOutbound public function Processes the outbound path. Overrides LanguageNegotiationUrl::processOutbound