Elgg  Version master
language.php
Go to the documentation of this file.
1 <?php
9 if (!$user instanceof \ElggUser) {
10  return;
11 }
12 
13 $who_can_change_language = elgg_get_config('who_can_change_language');
14 if ($who_can_change_language === 'nobody') {
15  return;
16 } elseif ($who_can_change_language === 'admin_only' && !elgg_is_admin_logged_in()) {
17  return;
18 }
19 
20 $options = elgg()->translator->getInstalledTranslations(elgg_is_admin_logged_in());
21 $options = array_intersect_key($options, array_flip(elgg()->translator->getAllowedLanguages()));
22 
23 if (count($options) < 2) {
24  return;
25 }
26 
28  '#type' => 'select',
29  '#label' => elgg_echo('user:language:label'),
30  'name' => 'language',
31  'value' => $user->language,
32  'options_values' => $options,
33 ];
34 
35 if (count($options) < 4) {
36  $field_options['#type'] = 'radio';
37  $field_options['align'] = 'horizontal';
38 }
39 
elgg
Definition: install.js:27
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1112
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$user
Provide a way of setting your language prefs.
Definition: language.php:8
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
$vars
Definition: theme.php:5
if(!$user instanceof\ElggUser) $who_can_change_language
Definition: language.php:13
if(count($options)< 2) $field_options
Definition: language.php:27