By plach on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.0-ALPHA3
Issue links:
Description:
The language_fallback_get_candidates() function has been moved onto the language manager and now accepts a $context parameter describing the context where fallback is applied:
<?php
public function getFallbackCandidates($langcode = NULL, array $context = array());
?>
The $context parameter is an associative array of arbitrary data that can be useful to determine the fallback sequence. The following keys are used in core:
langcode: The context language.operation: The name of the operation indicating the context where language fallback is being applied, e.g.'entity_view'.data: An arbitrary data structure that makes sense in the specified context, e.g. an entity.
Also hook_language_fallback_candidates_alter() now receives the $context parameter, and an operation-specific version of the hook is available if the operation key is defined:
<?php
/**
* Implements hook_language_fallback_candidates_OPERATION_alter().
*/
function foo_language_fallback_candidates_entity_view_alter(array &$candidates, array $context) {
// We know that the current OPERATION deals with entities so no need to check
// here.
if (!empty($context['data']) && $context['data']->entityType() == 'node') {
$candidates = array_reverse($candidates);
}
}
?>
Impacts:
Module developers