class LanguageNegotiationContentEntity extends LanguageNegotiationMethodBase implements OutboundPathProcessorInterface, LanguageSwitcherInterface, ContainerFactoryPluginInterface (View source)

Class for identifying the content translation language.

Constants

METHOD_ID

The language negotiation method ID.

QUERY_PARAMETER

The query string parameter.

Properties

protected LanguageManagerInterface $languageManager

The language manager.

from  LanguageNegotiationMethodBase
protected ConfigFactoryInterface $config

The configuration factory.

from  LanguageNegotiationMethodBase
protected AccountInterface $currentUser

The current active user.

from  LanguageNegotiationMethodBase
protected array $contentEntityPaths

A list of all the link paths of enabled content entities.

protected bool $hasLowerLanguageNegotiationWeightResult

Static cache for the language negotiation order check.

protected SplObjectStorage $paths

Static cache of outbound route paths per request.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

Methods

setLanguageManager(ConfigurableLanguageManagerInterface $language_manager)

Injects the language manager.

setConfig(ConfigFactoryInterface $config)

Injects the configuration factory.

setCurrentUser(AccountInterface $current_user)

Injects the current user.

persist(LanguageInterface $language)

Notifies the plugin that the language code it returned has been accepted.

__construct(EntityTypeManagerInterface $entity_type_manager)

Constructs a new LanguageNegotiationContentEntity instance.

create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

string
getLangcode(Request $request = NULL)

Performs language negotiation.

string
processOutbound(string $path, array $options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)

Processes the outbound path.

array
getLanguageSwitchLinks(Request $request, string $type, Url $url)

Returns language switch links.

bool
hasLowerLanguageNegotiationWeight()

Determines if content entity language negotiator has higher priority.

bool
meetsContentEntityRoutesCondition(Route $outbound_route, Request $request)

Determines if content entity route condition is met.

string
getContentEntityTypeIdForCurrentRequest(Request $request)

Returns the content entity type ID from the current request for the route.

array
getContentEntityPaths()

Returns the paths for the link templates of all content entities.

Details

setLanguageManager(ConfigurableLanguageManagerInterface $language_manager)

Injects the language manager.

Parameters

ConfigurableLanguageManagerInterface $language_manager

The language manager to be used to retrieve the language list and the already negotiated languages.

setConfig(ConfigFactoryInterface $config)

Injects the configuration factory.

Parameters

ConfigFactoryInterface $config

The configuration factory.

setCurrentUser(AccountInterface $current_user)

Injects the current user.

Parameters

AccountInterface $current_user

The current active user.

persist(LanguageInterface $language)

Notifies the plugin that the language code it returned has been accepted.

Parameters

LanguageInterface $language

The accepted language.

__construct(EntityTypeManagerInterface $entity_type_manager)

Constructs a new LanguageNegotiationContentEntity instance.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

static ContainerFactoryPluginInterface create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)

Creates an instance of the plugin.

Parameters

ContainerInterface $container

The container to pull out services used in the plugin.

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin ID for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

Return Value

ContainerFactoryPluginInterface

Returns an instance of this plugin.

string getLangcode(Request $request = NULL)

Performs language negotiation.

Parameters

Request $request

(optional) The current request. Defaults to NULL if it has not been initialized yet.

Return Value

string

A valid language code or FALSE if the negotiation was unsuccessful.

string processOutbound(string $path, array $options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)

Processes the outbound path.

Parameters

string $path

The path to process, with a leading slash.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'query': An array of query key/value-pairs (without any URL-encoding) to append to the URL.
  • 'fragment': A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character.
  • 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
  • 'language': An optional language object used to look up the alias for the URL. If $options['language'] is omitted, it defaults to the current language for the language type LanguageInterface::TYPE_URL.
  • 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
  • 'base_url': Only used internally by a path processor, for example, to modify the base URL when a language dependent URL requires so.
  • 'prefix': Only used internally, to modify the path when a language dependent URL requires so.
  • 'route': The route object for the given path. It will be set by \Drupal\Core\Routing\UrlGenerator::generateFromRoute().
Request $request

The HttpRequest object representing the current request.

BubbleableMetadata $bubbleable_metadata

(optional) Object to collect path processors' bubbleable metadata.

Return Value

string

The processed path.

Returns language switch links.

Parameters

Request $request

The current request.

string $type

The language type.

Url $url

The URL the switch links will be relative to.

Return Value

array

An array of link arrays keyed by language code.

protected bool hasLowerLanguageNegotiationWeight()

Determines if content entity language negotiator has higher priority.

The content entity language negotiator having higher priority than the url language negotiator, is a criteria in \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::processOutbound().

Return Value

bool

TRUE if the content entity language negotiator has higher priority than the url language negotiator, FALSE otherwise.

protected bool meetsContentEntityRoutesCondition(Route $outbound_route, Request $request)

Determines if content entity route condition is met.

Requirements: currently being on a content entity route and processing outbound url pointing to the same content entity.

Parameters

Route $outbound_route

The route object for the current outbound url being processed.

Request $request

The HttpRequest object representing the current request.

Return Value

bool

TRUE if the content entity route condition is met, FALSE otherwise.

protected string getContentEntityTypeIdForCurrentRequest(Request $request)

Returns the content entity type ID from the current request for the route.

Parameters

Request $request

The HttpRequest object representing the current request.

Return Value

string

The entity type ID for the route from the request.

protected array getContentEntityPaths()

Returns the paths for the link templates of all content entities.

Return Value

array

An array of all content entity type IDs, keyed by the corresponding link template paths.