You are here

function allowed_languages_pre_render_language_select in Allowed Languages 8

Pre-render function for the language select widget.

Removes any languages that the user is not allowed to create content for.

Parameters

array $element: The element render array.

Return value

array The modified render array.

1 string reference to 'allowed_languages_pre_render_language_select'
allowed_languages_field_widget_language_select_form_alter in ./allowed_languages.module
Apply a pre-render function to the language select field widget.

File

./allowed_languages.module, line 92
Contains allowed_languages.module.

Code

function allowed_languages_pre_render_language_select(array $element) {
  $user = allowed_languages_get_current_user();
  $allowed_languages = allowed_languages_get_allowed_languages_for_user($user);

  // Remove any languages that the user is not allowed to add content for.
  foreach ($element['value']['#options'] as $language_code => $language_option) {

    // If the language is allowed then continue.
    if (in_array($language_code, $allowed_languages)) {
      continue;
    }

    // Always allow the not specified and not applicable language options.
    if ($language_code === LanguageInterface::LANGCODE_NOT_SPECIFIED || $language_code === LanguageInterface::LANGCODE_NOT_APPLICABLE) {
      continue;
    }
    unset($element['value']['#options'][$language_code]);
  }
  return $element;
}