You are here

public function MiniorangeConfigOAuthClient::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/MiniorangeConfigOAuthClient.php, line 15

Class

MiniorangeConfigOAuthClient

Namespace

Drupal\oauth2_login\Form

Code

public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  global $base_url;
  \Drupal::configFactory()
    ->getEditable('oauth2_login.settings')
    ->set('miniorange_oauth_client_disabled', FALSE)
    ->save();
  $moTour = mo_saml_visualTour::genArray();
  $form['tourArray'] = array(
    '#type' => 'hidden',
    '#value' => $moTour,
  );
  $baseUrlValue = Utilities::getOAuthBaseURL($base_url);
  $login_path = '<a href=' . $baseUrlValue . '/moLogin>Enter what you want to display on the link</a>';
  $module_path = \Drupal::service('extension.list.module')
    ->getPath('oauth2_login');
  $miniorange_auth_client_callback_uri = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_oauth_client_base_url');
  $miniorange_auth_client_callback_uri = is_null($miniorange_auth_client_callback_uri) ? $miniorange_auth_client_callback_uri . "/mo_login" : $baseUrlValue . "/mo_login";
  \Drupal::configFactory()
    ->getEditable('oauth2_login.settings')
    ->set('miniorange_auth_client_callback_uri', $miniorange_auth_client_callback_uri)
    ->save();
  $attachments['#attached']['library'][] = 'oauth2_login/oauth2_login.admin';
  $form['markup_library'] = array(
    '#attached' => array(
      'library' => array(
        "oauth2_login/oauth2_login.oauth_config",
        "oauth2_login/oauth2_login.admin",
        "oauth2_login/oauth2_login.testconfig",
        "oauth2_login/oauth2_login.returnAttribute",
        "oauth2_login/oauth2_login.style_settings",
        "oauth2_login/oauth2_login.Vtour",
        "oauth2_login/mo-card",
      ),
    ),
  );
  $app_name = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_auth_client_app_name');
  $client_id = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_auth_client_client_id');
  if (!empty($app_name) && !empty($client_id)) {
    $disabled = TRUE;
  }
  $app_name_selected = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_auth_client_app_name');
  $client_id = \Drupal::config('oauth2_login.settings')
    ->get('miniorange_auth_client_client_id');
  if (!empty($app_name_selected) && !empty($client_id)) {
    $disabled = TRUE;
    $attributes_arr = array(
      'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
    );
  }
  else {
    $disabled = FALSE;
    $attributes_arr = array(
      'style' => 'width:73%;',
    );
  }
  $disableButton = NULL;
  if (empty($app_name_selected) || empty($client_id)) {
    $disableButton = 'disabled';
  }
  $form['mo_oauth_top_div'] = array(
    '#markup' => '<div class="mo_oauth_table_layout_1">',
  );
  $form['mo_oauth_inside_div'] = array(
    '#markup' => '<div class="mo_oauth_table_layout mo_oauth_container">',
  );
  $form['markup_top_vt_start'] = array(
    '#attached' => array(
      'library' => 'oauth2_login/oauth2_login.Vtour',
    ),
    '#markup' => '<div id="tabhead"><h3>CONFIGURE OAUTH APPLICATION &nbsp;&nbsp;
            <a id="showMetaButton" class="mo_oauth_btn mo_oauth_btn-primary mo_btn-sm" onclick="testConfig()" ' . $disableButton . '>Backup/Import</a>&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <hr><br></div>',
  );
  $form['markup_top_1'] = array(
    '#markup' => '
                <div border="1" id="backup_import_form" class="mo_oauth_backup_download">
				<h3>Backup/ Import Configurations</h3><hr><span class="mo_oauth_backup_cancel">
				<a id="hideMetaButton" class="mo_oauth_btn mo_oauth_btn-sm mo_oauth_btn-danger" onclick = "testConfig()">Cancel</a></span>',
  );
  $form['markup_1'] = array(
    '#markup' => '<br><br><div class="mo_saml_highlight_background_note_1"><p><b>NOTE: </b>This tab will help you to transfer your module configurations when you change your Drupal instance.
                          <br>Example: When you switch from test environment to production.<br>Follow these 3 simple steps to do that:<br>
                          <br><strong>1.</strong> Download module configuration file by clicking on the Download Configuration button given below.
                          <br><strong>2.</strong> Install the module on new Drupal instance.<br><strong>3.</strong> Upload the configuration file in Import module Configurations section.<br>
                          <br><b>And just like that, all your module configurations will be transferred!</b></p></div><br><div id="Exort_Configuration"><h3>Backup/ Export Configuration &nbsp;&nbsp;</h3><hr/><p>
                          Click on the button below to download module configuration.</p>',
  );
  $form['miniorange_saml_imo_option_exists_export'] = array(
    '#type' => 'submit',
    '#value' => t('Download Module Configuration'),
    '#submit' => array(
      '::miniorange_import_export',
    ),
    '#suffix' => '<br/><br/></div>',
  );
  $form['markup_prem_plan'] = array(
    '#markup' => '<div id="Import_Configuration"><br/><h3>Import Configuration</h3><hr><br>
                          <div class="mo_oauth_highlight_background_note_1"><b>Note: </b>Available in
                          <a href="' . $base_url . '/admin/config/people/oauth2_login/licensing">Standard, Premium and Enterprise</a> versions of the module</div>',
  );
  $form['markup_import_note'] = array(
    '#markup' => '<p>This tab will help you to<span style="font-weight: bold"> Import your module configurations</span> when you change your Drupal instance.</p>
                 <p>choose <b>"json"</b> Extened module configuration file and upload by clicking on the button given below. </p>',
  );
  $form['import_Config_file'] = array(
    '#type' => 'file',
    '#disabled' => TRUE,
  );
  $form['miniorange_saml_idp_import'] = array(
    '#type' => 'submit',
    '#value' => t('Upload'),
    '#disabled' => TRUE,
    '#suffix' => '<br><br></div></div><div id="clientdata">',
  );
  $form['miniorange_oauth_client_app_options'] = array(
    '#type' => 'value',
    '#id' => 'miniorange_oauth_client_app_options',
    '#value' => array(
      'Select' => t('Select'),
      'Azure AD' => t('Azure AD'),
      'Keycloak' => t('Keycloak'),
      'Salesforce' => t('Salesforce'),
      'Google' => t('Google'),
      'GitHub' => t('GitHub'),
      'Facebook' => t('Facebook'),
      'Box' => t('Box'),
      'Slack' => t('Slack'),
      'Discord' => t('Discord'),
      'Line' => t('Line'),
      'Wild Apricot' => t('Wild Apricot'),
      'Zendesk' => t('Zendesk'),
      'LinkedIn' => t('LinkedIn'),
      'Strava' => t('Strava'),
      'FitBit' => t('FitBit'),
      'Custom' => t('Custom OAuth 2.0 Provider'),
      'Azure AD B2C' => t('Azure AD B2C (Premium and Enterprise)'),
      'AWS Cognito' => t('AWS Cognito (Premium and Enterprise)'),
      'Onelogin' => t('Onelogin (Premium and Enterprise)'),
      'miniOrange' => t('miniOrange (Premium and Enterprise)'),
      'Custom_openid' => t('Custom OpenID Provider (We support OpenID protocol in Premium and Enterprise version)'),
    ),
  );
  $form['miniorange_oauth_client_app'] = array(
    '#title' => t('Select Application: '),
    '#id' => 'miniorange_oauth_client_app',
    '#type' => 'select',
    '#disabled' => $disabled,
    '#description' => "Select an OAuth Server",
    '#options' => $form['miniorange_oauth_client_app_options']['#value'],
    '#attributes' => $attributes_arr,
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_client_app'),
  );
  $form['mo_vt_id_start'] = array(
    '#markup' => '<div id = "mo_vt_callback_url">',
  );
  $form['miniorange_oauth_callback'] = array(
    '#type' => 'textfield',
    '#title' => t('Callback/Redirect URL: '),
    '#id' => 'callbackurl',
    '#default_value' => $miniorange_auth_client_callback_uri,
    '#disabled' => true,
    '#attributes' => array(
      'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
    ),
  );
  $form['mo_vt_id_end'] = array(
    '#markup' => '</div>',
  );
  $form['mo_vt_id_data'] = array(
    '#markup' => '<div id = "mo_vt_add_data">',
  );
  $form['miniorange_oauth_app_name'] = array(
    '#type' => 'textfield',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_app_name'),
    '#id' => 'miniorange_oauth_client_app_name',
    '#title' => t('Custom App Name: '),
    '#disabled' => $disabled,
    '#attributes' => $attributes_arr,
  );
  $form['miniorange_oauth_client_display_name'] = array(
    '#type' => 'textfield',
    '#id' => 'miniorange_oauth_client_display_name',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_display_name'),
    '#title' => t('Login link on the login page: '),
    '#description' => t('<b>Note:</b> By default the login link will appear on the user login page in this manner.'),
    '#attributes' => array(
      'style' => 'width:73%',
      'placeholder' => 'Login using ##app_name##',
    ),
  );
  $form['miniorange_oauth_client_id'] = array(
    '#type' => 'textfield',
    '#id' => 'miniorange_oauth_client_client_id',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_client_id'),
    '#title' => t('Client Id: '),
    '#description' => "You will get this value from your OAuth Server",
    '#attributes' => array(
      'style' => 'width:73%',
    ),
  );
  $form['miniorange_oauth_client_secret'] = array(
    '#type' => 'textfield',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_client_secret'),
    '#description' => "You will get this value from your OAuth Server",
    '#id' => 'miniorange_oauth_client_client_secret',
    '#title' => t('Client Secret: '),
    '#attributes' => array(
      'style' => 'width:73%',
    ),
  );
  $form['mo_vt_id_data1'] = array(
    '#markup' => '</div>',
  );
  $form['mo_vt_id_data2'] = array(
    '#markup' => '<div id = "mo_vt_add_data2">',
  );
  $form['miniorange_oauth_client_scope'] = array(
    '#type' => 'textfield',
    '#id' => 'miniorange_oauth_client_scope',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_scope'),
    '#description' => "Scope decides the range of data that you will be getting from your OAuth Provider",
    '#title' => t('Scope: <div class="mo_oauth_tooltip"><img src="' . $base_url . '/' . $module_path . '/includes/images/info.png" alt="info icon" height="15px" width="15px"></div><div class="mo_oauth_tooltiptext">The scopes may differ from server to server. In case you are not sure about what to enter, please contact us by sending a query from support button.</div>'),
    '#attributes' => array(
      'style' => 'width:73%',
    ),
  );
  $form['mo_vt_id_data2_end'] = array(
    '#markup' => '</div>',
  );
  $form['mo_vt_id_data3'] = array(
    '#markup' => '<div id = "mo_vt_add_data3">',
  );
  $form['miniorange_oauth_client_authorize_endpoint'] = array(
    '#type' => 'textfield',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_authorize_endpoint'),
    '#id' => 'miniorange_oauth_client_auth_ep',
    '#title' => t('Authorize Endpoint: '),
    '#attributes' => array(
      'style' => 'width:73%',
    ),
  );
  $form['miniorange_oauth_client_access_token_endpoint'] = array(
    '#type' => 'textfield',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_access_token_ep'),
    '#id' => 'miniorange_oauth_client_access_token_ep',
    '#title' => t('Access Token Endpoint: '),
    '#attributes' => array(
      'style' => 'width:73%',
    ),
  );
  $form['miniorange_oauth_client_userinfo_endpoint'] = array(
    '#type' => 'textfield',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_auth_client_user_info_ep'),
    '#id' => 'miniorange_oauth_client_user_info_ep',
    '#title' => t('Get User Info Endpoint: '),
    '#attributes' => array(
      'style' => 'width:73%',
    ),
  );
  $form['background_2'] = array(
    '#markup' => t('<b>Send Client ID and secret in: </b> <div class="mo_oauth_tooltip"><img src="' . $base_url . '/' . $module_path . '/includes/images/info.png" alt="info icon" height="15px" width="15px"></div><div class="mo_oauth_tooltiptext"><b>Note:</b> This option depends upon the OAuth provider. In case you are unaware about what to save, keeping this default is the best practice.</div>'),
  );
  $form['background_1'] = array(
    '#markup' => "<div class='mo_oauth_highlight_background_note_2'>",
  );
  $form['miniorange_oauth_send_with_header_oauth'] = array(
    '#type' => 'checkbox',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_send_with_header_oauth'),
    '#title' => t('<b>Header</b>'),
  );
  $form['miniorange_oauth_send_with_body_oauth'] = array(
    '#type' => 'checkbox',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_send_with_body_oauth'),
    '#title' => t('<b>Body</b>'),
  );
  $form['background_1_end'] = array(
    '#markup' => '</div>',
  );
  $form['mo_btn_breaks'] = array(
    '#markup' => "</div><br>",
  );
  $form['mo_vt_id_data4'] = array(
    '#markup' => '<div id = "mo_vt_add_data4">',
  );
  $form['miniorange_oauth_enable_login_with_oauth'] = array(
    '#type' => 'checkbox',
    '#default_value' => \Drupal::config('oauth2_login.settings')
      ->get('miniorange_oauth_enable_login_with_oauth'),
    '#title' => t('<b>Enable Login with OAuth</b>'),
  );
  $form['mo_btn_breaks2'] = array(
    '#markup' => "</div><br>",
  );
  $form['miniorange_oauth_client_config_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Configuration'),
    '#id' => 'button_config',
  );
  $baseUrlValue = Utilities::getOAuthBaseURL($base_url);
  $form['miniorange_oauth_client_test_config_button'] = array(
    '#value' => t('Test'),
    '#markup' => '<span id="base_Url" name="base_Url" data="' . $baseUrlValue . '"></span>
                                <a id="testConfigButton" class="mo_oauth_btn mo_oauth_btn-primary-color mo_oauth_btn-large mo_oauth_btn_fix">Test Configuration</a>',
  );
  $form['mo_reset'] = array(
    '#markup' => "<a class='mo_oauth_btn mo_oauth_btn-primary mo_oauth_btn-large' id ='vt_reset_config' href='" . $baseUrlValue . "/resetConfig'>Reset Configuration</a>",
  );
  $form['miniorange_oauth_login_link'] = array(
    '#id' => 'miniorange_oauth_login_link',
    '#markup' => "<br><br><br><br><div class='mo_oauth_instruction_style'>\n                <br><strong><div class='mo_custom_font_size_1'>Instructions to add login link to different pages in your Drupal site: </div></strong><br>\n                <div class='mo_custom_font_size_2'>After completing your configurations, by default you will see a login link on your drupal site's login page.\n                However, if you want to add login link somewhere else, please follow the below given steps:</div>\n                <div class='mo_custom_font_size_3'>\n                <li>Go to <b>Structure</b> -> <b>Blocks</b></li>\n                <li> Click on <b>Add block</b></li>\n                <li>Enter <b>Block Title</b> and the <b>Block description</b></li>\n                <li>Under the <b>Block body</b> add the following URL to add a login link:\n                    <ol> <h3><b>&lt;a href= '" . $baseUrlValue . "/moLogin'> Click here to Login&lt;/a&gt;</b></h3></ol>\n                </li>\n                <li>From the text filtered dropdown select either <b>Filtered HTML</b> or <b>Full HTML</b></li>\n                <li>From the division under <b>REGION SETTINGS</b> select where do you want to show the login link</li>\n                <li>Click on the <b>SAVE block</b> button to save your settings</li><br>\n                </div>\n                </div>",
    '#attributes' => array(),
  );
  $form['mo_header_style_end'] = array(
    '#markup' => '</div></div>',
  );
  Utilities::spConfigGuide($form, $form_state);
  $form['mo_markup_div_2_imp'] = array(
    '#markup' => '</div>',
  );
  Utilities::AddSupportButton($form, $form_state);
  return $form;
}