You are here

function allowed_languages_user_form_submit in Allowed Languages 8

Same name and namespace in other branches
  1. 2.x allowed_languages.module \allowed_languages_user_form_submit()

Allowed languages user form submit handler.

Parameters

array $form: The user form.

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

1 string reference to 'allowed_languages_user_form_submit'
allowed_languages_form_user_form_alter in ./allowed_languages.module
Add the allowed languages checkboxes to the user form.

File

./allowed_languages.module, line 172
Contains allowed_languages.module.

Code

function allowed_languages_user_form_submit(array &$form, FormStateInterface $form_state) {
  $languages = array_filter($form_state
    ->getValue([
    'allowed_languages',
    'languages',
  ], []));

  // If the al languages checkbox was checked then lets remove it to not have
  // it saved to the allowed languages.
  if (isset($languages['all'])) {
    unset($languages['all']);
  }

  /** @var \Drupal\user\UserInterface $account */
  $account = $form_state
    ->getFormObject()
    ->getEntity();
  if ($account
    ->hasField('allowed_languages')) {
    $account
      ->set('allowed_languages', array_values($languages))
      ->save();
  }
}