You are here

public static function LimitLanguageOptionsCallback::afterBuild in Language access 8

Alters the language widget options. This method is used in #after_build.

Parameters

array $element: The language form element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

Return value

array The language form element.

File

src/LimitLanguageOptionsCallback.php, line 53

Class

LimitLanguageOptionsCallback
Class that contains callbacks to alter language elements.

Namespace

Drupal\language_access

Code

public static function afterBuild(array $element, FormStateInterface $form_state) : array {
  $languages = \Drupal::languageManager()
    ->getLanguages();
  foreach (array_keys($element['value']['#options']) as $id) {
    if (isset($languages[$id]) && !$element['#for_user']
      ->hasPermission('access language ' . $id)) {
      unset($element['value']['#options'][$id]);
    }
  }
  unset($element['#for_user']);
  return $element;
}