You are here

public function MiniorangeMapping::buildForm in OAuth2 Login 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MiniorangeMapping.php, line 25
Contains \Drupal\miniorange_oauth_client\Form\MiniorangeGeneralSettings.

Class

MiniorangeMapping

Namespace

Drupal\oauth2_login\Form

Code

public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  global $base_url;
  $form['markup_library'] = [
    '#attached' => [
      'library' => [
        "oauth2_login/oauth2_login.admin",
        "oauth2_login/oauth2_login.style_settings",
        "oauth2_login/oauth2_login.Vtour",
      ],
    ],
  ];
  $form['header_top_style_1'] = [
    '#markup' => '<div class="mo_oauth_table_layout_1">',
  ];
  $form['markup_top'] = [
    '#markup' => '<div class="mo_oauth_table_layout mo_oauth_container">',
  ];
  $form['markup_top_vt_start'] = [
    '#markup' => '<h3>ATTRIBUTE MAPPING</h3><hr><br>',
  ];
  $email_attr = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_oauth_client_email_attr_val');
  $name_attr = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_oauth_client_name_attr_val');
  $form['miniorange_oauth_client_email_attr'] = [
    '#type' => 'textfield',
    '#title' => t('Email Attribute: '),
    '#default_value' => $email_attr,
    '#description' => 'This field is mandatory for login',
    '#required' => TRUE,
    '#attributes' => [
      'id' => 'mo_oauth_vt_attrn',
      'style' => 'width:73%;',
      'placeholder' => 'Enter Email Attribute',
    ],
  ];
  $form['miniorange_oauth_client_name_attr'] = [
    '#type' => 'textfield',
    '#title' => t('Username Attribute: '),
    '#description' => "<b>Note:</b> If this text field is empty, then by default email id will be the user's username",
    '#default_value' => $name_attr,
    '#attributes' => [
      'id' => 'mo_oauth_vt_attre',
      'style' => 'width:73%;',
      'placeholder' => 'Enter Username Attribute',
    ],
  ];
  $form['miniorange_oauth_client_attr_setup_button_2'] = [
    '#type' => 'submit',
    '#id' => 'button_config_center',
    '#value' => t('Save Configuration'),
    '#submit' => [
      '::miniorange_oauth_client_attr_setup_submit',
    ],
  ];
  $form['markup_cam'] = [
    '#markup' => '<br><h3>CUSTOM ATTRIBUTE MAPPING</h3><hr><br>
                    <div class="mo_saml_highlight_background_note_1">Define your mapping in hook_oauth2_login_field_mapping(). See the example:<br>function MYMODULE_hook_oauth2_login_field_mapping(){
  <br>return [\'REMOTE_FIELD\', \'LOCAL FIELD\'];
<br>} </div><br>',
  ];
  $output = '';
  $hook1 = 'oauth2_login_field_mapping';
  $implementations = \Drupal::moduleHandler()
    ->getImplementations($hook1);
  foreach ($implementations as $implementation) {
    $func = $implementation . '_' . $hook1;
    $output = '<li>' . $func . '</li>';
  }
  $form['markup_hook'] = [
    '#markup' => '<h3>Hooks found.</h3><ul>' . $output . '</ul>',
  ];
  $form['markup_role'] = [
    '#markup' => '<br><h3>Custom Role Mapping</h3><hr><br>',
  ];
  $form['miniorange_disable_attribute'] = [
    '#type' => 'checkbox',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_disable_attribute'),
    '#title' => t('Do not update existing user&#39;s role.'),
  ];
  $form['miniorange_oauth_disable_role_update'] = [
    '#type' => 'checkbox',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_disable_role_update'),
    '#title' => t('Check this option if you do not want to update user role if roles not mapped. '),
  ];
  $form['miniorange_oauth_disable_autocreate_users'] = [
    '#type' => 'checkbox',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_disable_autocreate_users'),
    '#title' => t('Check this option if you want to disable <b>auto creation</b> of users if user does not exist. '),
  ];
  $mrole = user_role_names($membersonly = TRUE);
  $drole = array_values($mrole);
  $form['miniorange_oauth_default_mapping'] = [
    '#type' => 'select',
    '#id' => 'miniorange_oauth_client_app',
    '#title' => t('Select default group for the new users'),
    '#options' => $mrole,
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_default_mapping'),
    '#attributes' => [
      'style' => 'width:73%;',
    ],
  ];
  foreach ($mrole as $roles) {
    $rolelabel = str_replace(' ', '', $roles);
    $form['miniorange_oauth_role_' . $rolelabel] = [
      '#type' => 'textfield',
      '#title' => t($roles),
      '#default_value' => \Drupal::config('oauth2_login.settings')
        ->get('miniorange_oauth_role_' . $rolelabel, ''),
      '#attributes' => [
        'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
        'placeholder' => 'Semi-colon(;) separated Group/Role value for ' . $roles,
      ],
    ];
  }
  $form['markup_role_signin'] = [
    '#markup' => '<br><h3>Custom Login/Logout (Optional)</h3><hr>',
  ];
  $form['miniorange_oauth_client_login_url'] = [
    '#type' => 'textfield',
    '#id' => 'text_field2',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_client_login_url'),
    '#required' => FALSE,
    '#attributes' => [
      'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
      'placeholder' => 'Enter Login URL',
    ],
  ];
  $form['miniorange_oauth_client_logout_url'] = [
    '#type' => 'textfield',
    '#id' => 'text_field3',
    '#required' => FALSE,
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_client_logout_url'),
    '#attributes' => [
      'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
      'placeholder' => 'Enter Logout URL',
    ],
  ];
  $form['markup_role_break'] = [
    '#markup' => '<br>',
  ];
  $form['miniorange_oauth_client_attr_setup_button'] = [
    '#type' => 'submit',
    '#id' => 'button_config_center',
    '#value' => t('Save Configuration'),
    '#submit' => [
      '::miniorange_oauth_client_attr_setup_submit2',
    ],
  ];
  $form['mo_header_style_end'] = [
    '#markup' => '</div>',
  ];
  Utilities::show_attr_list_from_idp($form, $form_state);
  $form['miniorange_idp_guide_link_end'] = [
    '#markup' => '</div>',
  ];
  Utilities::AddSupportButton($form, $form_state);
  return $form;
}