You are here

function cms_content_sync_user_password_submit in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x cms_content_sync.module \cms_content_sync_user_password_submit()
  2. 2.0.x cms_content_sync.module \cms_content_sync_user_password_submit()

Update the password at Sync Core if it's necessary for authentication.

Parameters

$form:

\Drupal\Core\Form\FormStateInterface $form_state:

1 string reference to 'cms_content_sync_user_password_submit'
cms_content_sync_form_alter in ./cms_content_sync.module
1) Make sure the user is informed that content will not only be deleted on this * instance but also on all connected instances if configured that way.

File

./cms_content_sync.module, line 1246
Module file for cms_content_sync.

Code

function cms_content_sync_user_password_submit(&$form, FormStateInterface $form_state) {
  if (!_cms_content_sync_is_installed()) {
    return;
  }
  $uid = $form_state
    ->getValue('uid');
  if (CMS_CONTENT_SYNC_USER_ID == $uid) {
    $new_data = [
      'userName' => $form_state
        ->getValue('name'),
      'userPass' => $form_state
        ->getValue('pass'),
    ];

    // If password wasn't changed then value will be empty and we don't need it.
    $new_data = array_filter($new_data);
    $new_data = cms_content_sync_encrypt_values($new_data);
    $userId = $form_state
      ->getValue('uid');
    $userData = Drupal::service('user.data');
    $old_data = $userData
      ->get('cms_content_sync', $userId, 'sync_data');
    $new_data = array_replace($old_data, $new_data);
    $userData
      ->set('cms_content_sync', $userId, 'sync_data', $new_data);
    $flows = Flow::getAll();
    foreach ($flows as $flow) {
      $flow
        ->save();
    }
  }
}