You are here

function social_auth_extra_form_user_form_alter in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  2. 8 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  3. 8.2 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  4. 8.3 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  5. 8.5 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  6. 8.6 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  7. 8.7 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()
  8. 8.8 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_form_user_form_alter()

Implements hook_form_FORM_ID_alter() for user_form().

File

modules/custom/social_auth_extra/social_auth_extra.module, line 282
Contains social_auth_extra.module.

Code

function social_auth_extra_form_user_form_alter(&$form, FormStateInterface $form_state) {
  $account = $form_state
    ->getFormObject()
    ->getEntity();
  $network_manager = \Drupal::service('plugin.network.manager');
  $networks = $network_manager
    ->getDefinitions();
  if ($account
    ->id()) {
    if ($networks) {
      $form['social_login_connections'] = [
        '#type' => 'fieldset',
        '#title' => t('Social Log in Connections'),
      ];
      foreach ($networks as $network) {
        $instance = $network_manager
          ->createInstance($network['id']);
        if (!$instance
          ->isActive()) {
          continue;
        }
        $user_manager = \Drupal::service($network['id'] . '.user_manager');
        $user_manager
          ->setAccount($account);
        $form['social_login_connections'][$network['id']] = [
          '#type' => 'item',
          '#social_linkitem' => TRUE,
          '#title' => $network['social_network'],
        ];
        if ($user_manager
          ->getAccountId()) {
          $form['social_login_connections'][$network['id']]['link'] = [
            '#type' => 'link',
            '#title' => t('Unlink'),
            '#attributes' => [
              'class' => [
                'btn btn-default btn-social-linking',
              ],
            ],
            '#url' => Url::fromRoute($network['id'] . '.user_unlink'),
          ];
        }
        else {
          $form['social_login_connections'][$network['id']]['link'] = [
            '#type' => 'link',
            '#title' => t('Link'),
            '#attributes' => [
              'class' => [
                'btn btn-flat btn-social-linking',
              ],
            ],
            '#url' => Url::fromRoute($network['id'] . '.user_link'),
          ];
        }
      }

      // If there are no any active network, hide fieldset.
      if (empty(array_intersect_key($networks, $form['social_login_connections']))) {
        unset($form['social_login_connections']);
      }
    }
    if (!$account
      ->get('pass')->value) {
      $form['account']['current_pass']['#access'] = FALSE;
      $form_state
        ->set('user_pass_reset', TRUE);
    }
  }
}