From c0ad91bf5a0fff9b99a38e3702d17f1e9af6474a Mon Sep 17 00:00:00 2001 From: Purvashende <purvashende414@gmail.com> Date: Mon, 3 Feb 2025 14:19:07 +0530 Subject: [PATCH] PHPCS fixes and UI changes --- .../schema/rest_api_authentication.schema.yml | 8 +- ...pi_authentication.basic_style_settings.css | 12 +- ...rest_api_authentication.style_settings.css | 5 - rest_api_authentication.routing.yml | 6 +- src/AdvancedSettingsForm.php | 11 +- .../RestApiAuthenticationController.php | 29 +++- src/CustomerSetupForm.php | 107 -------------- src/Form/MiniOrangeAPIAuth.php | 22 ++- src/Form/MiniornageAPIAuthnRequestSupport.php | 5 +- src/Form/MiniornageAPIAuthnRequestTrial.php | 75 +++++++--- src/MiniorangeApiAuthSupport.php | 3 +- src/MiniorangeRestAPICustomer.php | 132 ------------------ src/MoHeadlessIntegration.php | 85 +++++++---- src/RequestForDemoForm.php | 8 +- src/SetupAuthenticationForm.php | 8 +- src/UpgradePlansForm.php | 75 +++++----- src/Utilities.php | 19 ++- 17 files changed, 253 insertions(+), 357 deletions(-) delete mode 100644 src/CustomerSetupForm.php delete mode 100644 src/MiniorangeRestAPICustomer.php diff --git a/config/schema/rest_api_authentication.schema.yml b/config/schema/rest_api_authentication.schema.yml index 55afb56..e7f62b6 100644 --- a/config/schema/rest_api_authentication.schema.yml +++ b/config/schema/rest_api_authentication.schema.yml @@ -1,5 +1,5 @@ rest_api_authentication.settings: - type: mapping + type: config_object label: Settings mapping: rest_api_authentication_customer_admin_email: @@ -14,3 +14,9 @@ rest_api_authentication.settings: type: string rest_api_authentication_status: type: string + enable_authentication: + type: integer + authentication_method: + type: integer + api_token: + type: string diff --git a/css/rest_api_authentication.basic_style_settings.css b/css/rest_api_authentication.basic_style_settings.css index c9f86e7..b3a938a 100644 --- a/css/rest_api_authentication.basic_style_settings.css +++ b/css/rest_api_authentication.basic_style_settings.css @@ -7,10 +7,7 @@ padding: 0.55em; width: 97%; } -.mo_rest_api_authn_background { - background-color: #f3f4f9 !important; - padding: 0.5%; -} + .td-class { padding: 0%; } @@ -18,3 +15,10 @@ #module_background { background-color: black; } +@media (prefers-color-scheme: dark) { + .gin--dark-mode .mo_rest_api_highlight_background_note_1 { + background-color: #2c2c2c; + color: white; + border: 1px solid #76777b; + } +} diff --git a/css/rest_api_authentication.style_settings.css b/css/rest_api_authentication.style_settings.css index 571cb3a..9fa85a2 100644 --- a/css/rest_api_authentication.style_settings.css +++ b/css/rest_api_authentication.style_settings.css @@ -3,7 +3,6 @@ } #pricing-table li { height: 40px; - color: black; text-align: center; overflow: hidden; } @@ -59,7 +58,6 @@ #pricing-table .pricing .pricing-list { padding: 20px 0 40px 0; background: #c4baba1c; - border: 1px solid #e3e3e3; } #pricing-table .pricing .pricing-list ul { padding: 0px; @@ -70,8 +68,6 @@ } #pricing-table .pricing .pricing-list ul li { list-style: none; - border-bottom: 1px solid #eaeceb; - color: black; font-size: 15px; line-height: 42px; } @@ -80,7 +76,6 @@ } #pricing-table .pricing .pricing-list ul li i { margin-right: 12px; - color: #bdc3c7; } #pricing-table .pricing .pricing-list ul li span { color: #34495e; diff --git a/rest_api_authentication.routing.yml b/rest_api_authentication.routing.yml index a0a460a..a72f054 100644 --- a/rest_api_authentication.routing.yml +++ b/rest_api_authentication.routing.yml @@ -1,14 +1,14 @@ rest_api_authentication.auth_settings: path: /admin/config/people/rest_api_authentication/auth_settings defaults: - _title: 'miniOrange API Authentication <a class="button button--primary js-form-submit form-submit use-ajax mo_top_bar_button" href="auth_settings/requestSupport">Contact Us</a><a class="button button--primary js-form-submit form-submit use-ajax mo_top_bar_button" href="auth_settings/requestFreeTrial">Request 7-days trial</a><a class="button js-form-submit form-submit mo_top_bar_button" href="?tab=edit-upgrade-plans">Upgrade Plans</a>' + _title: 'miniOrange API Authentication <a class="button button--primary js-form-submit form-submit use-ajax mo_top_bar_button" href="requestSupport">Contact Us</a><a class="button button--primary js-form-submit form-submit use-ajax mo_top_bar_button" href="requestFreeTrial">Request 7-days trial</a><a class="button js-form-submit form-submit mo_top_bar_button" href="?tab=edit-upgrade-plans">Upgrade Plans</a>' _form: \Drupal\rest_api_authentication\Form\MiniOrangeAPIAuth requirements: _permission: 'administer site configuration' #Route for Support Request/Contact Us rest_api_authentication.request_api_support: - path: /admin/config/people/rest_api_authentication/auth_settings/requestSupport + path: /admin/config/people/rest_api_authentication/requestSupport defaults: _title: 'miniOrange API Authentication Request Support' _controller: '\Drupal\rest_api_authentication\Controller\RestApiAuthenticationController::openSupportRequestForm' @@ -17,7 +17,7 @@ rest_api_authentication.request_api_support: #Route for Trial Request rest_api_authentication.request_trial: - path: /admin/config/people/rest_api_authentication/auth_settings/requestFreeTrial + path: /admin/config/people/rest_api_authentication/requestFreeTrial defaults: _title: 'miniOrange API Authentication Trial Request' _controller: '\Drupal\rest_api_authentication\Controller\RestApiAuthenticationController::openTrialRequestForm' diff --git a/src/AdvancedSettingsForm.php b/src/AdvancedSettingsForm.php index c8c2522..4b1dc33 100644 --- a/src/AdvancedSettingsForm.php +++ b/src/AdvancedSettingsForm.php @@ -3,6 +3,7 @@ namespace Drupal\rest_api_authentication; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; /** * Advanced setting form. @@ -21,7 +22,7 @@ class AdvancedSettingsForm { * The modified form array with the advanced settings elements added. */ public static function insertForm(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $disabled = TRUE; $form['advancedsettings'] = [ '#type' => 'details', @@ -31,7 +32,7 @@ class AdvancedSettingsForm { ]; $form['advancedsettings']['support_container_outline']['publisher'] = [ - '#markup' => '<b>ADVANCED SETTINGS:</b> These features are present in the <a href = "' . $base_url . '/admin/config/people/rest_api_authentication/auth_settings?tab=edit-upgrade-plans"><b>PREMIUM</b></a> version of the module<hr><br><div class="mo_rest_api_highlight_background_note_1">Need any help? Just send us a query and we will get back to you soon.<br /></div><br>', + '#markup' => t('<b>ADVANCED SETTINGS: </b>These features are present in the <a href = "' . $base_url . '/admin/config/people/rest_api_authentication/auth_settings?tab=edit-upgrade-plans"><b> PREMIUM </b></a> version of the module <hr><br><div class="mo_rest_api_highlight_background_note_1"> Need any help? Just send us a query and we will get back to you soon. <br /></div><br>') ]; $form['advancedsettings']['support_container_outline']['custom_headers'] = [ '#type' => 'details', @@ -112,7 +113,7 @@ class AdvancedSettingsForm { $form['advancedsettings']['support_container_outline']['list_apis'] = [ '#type' => 'details', '#title' => t('Restrict custom APIs'), - '#description' => t('Custom APIs mentioned here will be restricted. You can and multiple APIs using ";" as a separator'), + '#description' => t('<b>Note: </b>To enable this feature, please check the <b>Any Other/Custom APIs</b> checkbox under the <b>APIs to be Restricted</b> details.<br>'), ]; $form['advancedsettings']['support_container_outline']['list_apis']['custom_api_textarea'] = [ '#type' => 'textarea', @@ -121,9 +122,11 @@ class AdvancedSettingsForm { '#title' => t('You can add the APIs here:'), '#attributes' => [ 'style' => 'width:100%', - 'placeholder' => 'You can also add multiple APIs using a ; as a separator', + 'placeholder' => 'You can also add multiple APIs, each on a new line.', ], + '#description' => t("Specify page paths one per line and use <b>'*'</b> as a wildcard. For example, to restrict access to all routes under <b>'/abc'</b>, use the wildcard url <b>'/abc/*'</b>."), ]; + $form['advancedsettings']['support_container_outline']['list_apis']['token_submit_key3'] = [ '#type' => 'submit', '#button_type' => 'primary', diff --git a/src/Controller/RestApiAuthenticationController.php b/src/Controller/RestApiAuthenticationController.php index 91e65e1..d9dc456 100644 --- a/src/Controller/RestApiAuthenticationController.php +++ b/src/Controller/RestApiAuthenticationController.php @@ -7,6 +7,7 @@ use Drupal\Core\Ajax\OpenModalDialogCommand; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Form\FormBuilderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** * Controller for the rest api authentication module. @@ -19,11 +20,19 @@ class RestApiAuthenticationController extends ControllerBase { */ protected $formBuilder; + /** + * The Request Stack Service. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + /** * Constructor. */ - public function __construct(FormBuilderInterface $form_builder,) { + public function __construct(FormBuilderInterface $form_builder, RequestStack $request_stack) { $this->formBuilder = $form_builder; + $this->requestStack = $request_stack; } /** @@ -32,6 +41,7 @@ class RestApiAuthenticationController extends ControllerBase { public static function create(ContainerInterface $container) { return new static( $container->get('form_builder'), + $container->get('request_stack') ); } @@ -44,7 +54,13 @@ class RestApiAuthenticationController extends ControllerBase { public function openSupportRequestForm() { $response = new AjaxResponse(); $modal_form = $this->formBuilder->getForm('\Drupal\rest_api_authentication\Form\MiniornageAPIAuthnRequestSupport'); - $response->addCommand(new OpenModalDialogCommand('Support Request/Contact Us', $modal_form, ['width' => '40%'])); + $request = $this->requestStack->getCurrentRequest(); + if ($request->isXmlHttpRequest()) { + $response->addCommand(new OpenModalDialogCommand($this->t('Support Request/Contact Us'), $modal_form, ['width' => '40%'])); + } + else { + $response = $modal_form; + } return $response; } @@ -57,7 +73,14 @@ class RestApiAuthenticationController extends ControllerBase { public function openTrialRequestForm() { $response = new AjaxResponse(); $modal_form = $this->formBuilder->getForm('\Drupal\rest_api_authentication\Form\MiniornageAPIAuthnRequestTrial'); - $response->addCommand(new OpenModalDialogCommand('Request 7-Days Full Feature Trial License', $modal_form, ['width' => '40%'])); + $request = $this->requestStack->getCurrentRequest(); + + if ($request->isXmlHttpRequest()) { + $response->addCommand(new OpenModalDialogCommand('Request 7-Days Full Feature Trial License', $modal_form, ['width' => '40%'])); + } + else { + $response = $modal_form; + } return $response; } diff --git a/src/CustomerSetupForm.php b/src/CustomerSetupForm.php deleted file mode 100644 index 88a3b29..0000000 --- a/src/CustomerSetupForm.php +++ /dev/null @@ -1,107 +0,0 @@ -<?php - -namespace Drupal\rest_api_authentication; - -use Drupal\Core\Form\FormStateInterface; - -/** - * Provides the customer setup form. - */ -class CustomerSetupForm { - - /** - * Builds the customer setup form. - * - * @param array $form - * Stores the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * Stores the current state of the form. - * - * @return array - * The modified form array. - */ - public static function insertForm(array &$form, FormStateInterface $form_state) { - $current_status = \Drupal::config('rest_api_authentication.settings')->get('rest_api_authentication_status'); - $form['customersetup'] = [ - '#type' => 'details', - '#title' => t('Register/Login'), - '#open' => TRUE, - '#group' => 'verticaltabs', - ]; - if ($current_status == 'PLUGIN_CONFIGURATION') { - $form['customersetup']['customer_setup_container_outline']['markup_support_1'] = [ - '#markup' => '<div class="mo_rest_welcome_message">Thank you for registering with miniOrange</div><br><br><h4>Your Profile: </h4>', - ]; - $header = [ - 'email' => [ - 'data' => t('Customer Email'), - ], - 'customerid' => [ - 'data' => t('Customer ID'), - ], - 'module_version' => [ - 'data' => t('Module Version'), - ], - 'php_version' => [ - 'data' => t('PHP Version'), - ], - 'drupal_version' => [ - 'data' => t('Drupal Version'), - ], - ]; - - $options = []; - $modules_info = \Drupal::service('extension.list.module')->getExtensionInfo('rest_api_authentication'); - $options[0] = [ - 'email' => \Drupal::config('rest_api_authentication.settings')->get('rest_api_authentication_customer_admin_email'), - 'customerid' => \Drupal::config('rest_api_authentication.settings')->get('rest_api_authentication_customer_id'), - 'module_version' => $modules_info['version'], - 'php_version' => phpversion(), - 'drupal_version' => \Drupal::VERSION, - - ]; - $form['customersetup']['customer_setup_container_outline']['customerinfo'] = [ - '#theme' => 'table', - '#header' => $header, - '#rows' => $options, - '#suffix' => '<br>', - ]; - \Drupal::configFactory()->getEditable('rest_api_authentication.settings')->set('rest_api_authentication_status', $current_status)->save(); - } - else { - $form['customersetup']['customer_setup_container_outline']['markup_support_1'] = [ - '#markup' => '<b>LOGIN TO YOUR ACCOUNT USING THE MINIORANGE CREDENTIALS</b><hr><br><div class="mo_rest_api_highlight_background_note_1">If you do not have an account with us yet, please click on the link <a href="' . MiniorangeApiAuthConstants::CREATE_ACCOUNT . '" target="_blank">here</a><br>In case you are facing any issues while trying to configure or use our module, just send us a request and we will get back to you right away.<br /></div><br>', - ]; - - $form['customersetup']['customer_setup_container_outline']['rest_api_authentication_user_email'] = [ - '#type' => 'textfield', - '#id' => 'general_text_field', - '#title' => t('Email:'), - '#prefix' => '<br>', - '#attributes' => ['placeholder' => 'Enter your Email here', 'style' => 'width: 70%'], - ]; - $form['customersetup']['customer_setup_container_outline']['rest_api_authentication_user_password'] = [ - '#type' => 'password', - '#id' => 'general_text_field', - '#title' => t('Password:'), - '#attributes' => ['placeholder' => 'Enter your Password here', 'style' => 'width: 70%'], - ]; - - $form['customersetup']['customer_setup_container_outline']['rest_api_authentication_activate_module_submit'] = [ - '#type' => 'submit', - '#prefix' => '<table><tr><td>', - '#button_type' => 'primary', - '#suffix' => '</td><td>', - '#value' => t('Login'), - '#submit' => ['::activateModuleRequest'], - ]; - $form['customersetup']['header_bottom_create_account'] = [ - '#markup' => '<a href="' . MiniorangeApiAuthConstants::CREATE_ACCOUNT . '" target="_blank"> Create a new account</a>', - '#suffix' => '</td></tr></table>', - ]; - return $form; - } - return $form; - } - -} diff --git a/src/Form/MiniOrangeAPIAuth.php b/src/Form/MiniOrangeAPIAuth.php index 6007d41..e60a915 100644 --- a/src/Form/MiniOrangeAPIAuth.php +++ b/src/Form/MiniOrangeAPIAuth.php @@ -8,8 +8,6 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\rest_api_authentication\AdvancedSettingsForm; -use Drupal\rest_api_authentication\CustomerSetupForm; -use Drupal\rest_api_authentication\MiniorangeRestAPICustomer; use Drupal\rest_api_authentication\MoHeadlessIntegration; use Drupal\rest_api_authentication\RequestForDemoForm; use Drupal\rest_api_authentication\SetupAuthenticationForm; @@ -18,6 +16,8 @@ use Drupal\rest_api_authentication\Utilities; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RequestStack; +use Drupal\Core\Url; + /** * Provides a form for configuring MiniOrange API Authentication module. @@ -103,9 +103,7 @@ class MiniOrangeAPIAuth extends FormBase { $current_request = $this->requestStack->getCurrentRequest(); $tab = $current_request->query->get('tab'); $tab = (isset($tab)) ? ($tab) : ('edit-api-auth'); - $form['rest_api_authentication_background'] = [ - '#markup' => '<div class="mo_rest_api_authn_background">', - ]; + $form['verticaltabs'] = [ '#type' => 'vertical_tabs', '#default_tab' => $tab, @@ -126,9 +124,6 @@ class MiniOrangeAPIAuth extends FormBase { // Builds and inserts the Upgrade Plans form. UpgradePlansForm::insertForm($form, $form_state); - $form['rest_api_authentication_background_end'] = [ - '#markup' => '</div>', - ]; return $form; } @@ -144,7 +139,7 @@ class MiniOrangeAPIAuth extends FormBase { * return nothing. */ public function restApiAuthenticationSaveBasicConfig(array &$form, FormStateInterface $form_state): void { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $form_input = $form_state->getValues(); $enable_authentication = $form_input['enable_authentication']; @@ -166,7 +161,7 @@ class MiniOrangeAPIAuth extends FormBase { * return nothing. */ public function restApiAuthenticationGenerateApiToken(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $api_key = Utilities::generateRandom(64); $this->configFactory->getEditable('rest_api_authentication.settings') ->set('api_token', $api_key) @@ -180,7 +175,7 @@ class MiniOrangeAPIAuth extends FormBase { * {@inheritDoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $list_of_apis = $form['advancedsettings']['support_container_outline']['list_apis']['api_textarea']['#value']; $api_access = $form['advancedsettings']['support_container_outline']['list_apis']['settings']['#value']; $this->configFactory->getEditable('rest_api_authentication.settings') @@ -195,7 +190,7 @@ class MiniOrangeAPIAuth extends FormBase { * Save the basic authentication method. */ public function restApiAuthenticationSaveBasicAuthConf(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $this->configFactory->getEditable('rest_api_authentication.settings')->set('authentication_method', 0)->save(); $this->messenger->addMessage($this->t('Configurations saved successfully.')); $response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-api-auth"); @@ -206,7 +201,7 @@ class MiniOrangeAPIAuth extends FormBase { * Send a request for Demo. */ public function savedDemoRequest(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $email = trim($form['demo']['container_outline']['rest_api_authentication_email_address']['#value']); $phone = $form['demo']['container_outline']['rest_api_authentication_phone_number']['#value']; $query = trim($form['demo']['container_outline']['rest_api_authentication_demo_query']['#value']); @@ -214,4 +209,5 @@ class MiniOrangeAPIAuth extends FormBase { $response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-demo"); $response->send(); } + } diff --git a/src/Form/MiniornageAPIAuthnRequestSupport.php b/src/Form/MiniornageAPIAuthnRequestSupport.php index b9e568d..59ec24e 100644 --- a/src/Form/MiniornageAPIAuthnRequestSupport.php +++ b/src/Form/MiniornageAPIAuthnRequestSupport.php @@ -8,12 +8,15 @@ use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\rest_api_authentication\MiniorangeApiAuthSupport; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides form - Requesting support for MiniOrange API Authentication module. */ class MiniornageAPIAuthnRequestSupport extends FormBase { + use StringTranslationTrait; + /** * {@inheritDoc} */ @@ -42,7 +45,7 @@ class MiniornageAPIAuthnRequestSupport extends FormBase { ]; $form['markup_1'] = [ - '#markup' => $this->t('<p>Need any help? We can help you with configuring <strong>Drupal API Authentication module</strong> on your site. Just send us a query and we will get back to you right away.</p>'), + '#markup' => $this->t('<p>Need any help? We can help you with configuring <strong> Drupal API Authentication module </strong> on your site. Just send us a query and we will get back to you right away.'), ]; $form['rest_api_authentication_support_email_address'] = [ '#type' => 'email', diff --git a/src/Form/MiniornageAPIAuthnRequestTrial.php b/src/Form/MiniornageAPIAuthnRequestTrial.php index fe54ff8..2603562 100644 --- a/src/Form/MiniornageAPIAuthnRequestTrial.php +++ b/src/Form/MiniornageAPIAuthnRequestTrial.php @@ -11,8 +11,8 @@ use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Url; use Drupal\rest_api_authentication\MiniorangeApiAuthSupport; -use Drupal\user\Entity\User; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Form for the requesting the trial request. @@ -24,6 +24,7 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { * @var \Drupal\Core\Messenger\MessengerInterface */ protected $messenger; + use StringTranslationTrait; /** * Constructor. @@ -68,7 +69,7 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { 'option2' => $this->t('On-Premise'), ], '#default_value' => ($form_state->getValue('radio_option')) ? $form_state->getValue('radio_option') : 'option1', - '#attributes' => array('class' => array('container-inline'),), + '#attributes' => ['class' => ['container-inline']], '#ajax' => [ 'callback' => '::updateFormElements', 'wrapper' => 'additional-fields-wrapper', @@ -91,8 +92,9 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { 'visible' => [ ':input[name="radio_option"]' => ['value' => 'option2'], ], - 'required' => array( - ':input[name="radio_option"]' => ['value' => 'option2'],), + 'required' => [ + ':input[name="radio_option"]' => ['value' => 'option2'], + ], ], ]; @@ -109,13 +111,19 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { 'visible' => [ ':input[name="radio_option"]' => ['value' => 'option2'], ], - 'required' => array( - ':input[name="radio_option"]' => ['value' => 'option2'],), + 'required' => [ + ':input[name="radio_option"]' => ['value' => 'option2'], + ], ], ]; $form['rest_api_authentication_trial_note'] = [ - '#markup' => $this->t('<div>If you have any questions or in case you need any sort of assistance in configuring our module according to your requirements, you can get in touch with us on <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a> and we will assist you further.</div>'), + '#markup' => + '<div>' . + $this->t('If you have any questions or in case you need any sort of assistance in configuring our module according to your requirements, you can get in touch with us on <a href="mailto:@email">@email</a> and we will assist you further.', [ + '@email' => 'drupalsupport@xecurify.com', + ]) . + '</div>', '#states' => [ 'visible' => [ ':input[name="radio_option"]' => ['value' => 'option2'], @@ -127,16 +135,17 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { '#type' => 'submit', '#value' => $this->t('Go to Sandbox'), '#attributes' => [ - 'class' => ['option1-submit','use-ajax', 'button--primary'], - 'formtarget' => '_blank' + 'class' => ['option1-submit', 'use-ajax', 'button--primary'], + 'formtarget' => '_blank', ], '#prefix' => '<div class="option1-submit-wrapper">', '#suffix' => '</div>', '#states' => [ 'visible' => [ - ':input[name="radio_option"]' => ['value' => 'option1'],], + ':input[name="radio_option"]' => ['value' => 'option1'], + ], ], - '#submit' => ['::goToSandbox',], + '#submit' => ['::goToSandbox'], ]; $form['submit_button_other_options'] = [ @@ -162,15 +171,30 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { return $form; } - public static function getEmail(){ + /** + * Returns the email address. + * + * @return string|null + * The email address, or an empty string if invalid. + */ + public static function getEmail() { $user = \Drupal::currentUser()->getEmail(); $email = \Drupal::config('rest_api_authentication.settings')->get('rest_api_authentication_customer_admin_email'); $email = !empty($email) ? $email : $user; $email = preg_match('/^(?!.*(?:noreply|no-reply)).*$/i', $email) ? $email : ''; return $email; } + + /** + * Return the response and redirect the user to the sandbox. + * + * @param array $form + * The form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state object. + */ public function goToSandbox(array $form, FormStateInterface $form_state) { - $url = Url::fromUri('https://playground.miniorange.com/drupal.php',[ + $url = Url::fromUri('https://playground.miniorange.com/drupal.php', [ 'query' => [ 'email' => self::getEmail(), 'mo_module' => 'rest_api_authentication', @@ -180,13 +204,25 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { $response = new TrustedRedirectResponse($url); $form_state->setResponse($response); } + + /** + * Update the form elements based on the selected option. + * + * @param array $form + * The form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state object. + * + * @return mixed + * The updated form element. + */ public function updateFormElements(array &$form, FormStateInterface $form_state) { $selected_value = $form_state->getValue('radio_option'); if ($selected_value === 'option1') { - $form['actions']['send']['submit']['#value'] = t('Confirm Option 1'); + $form['actions']['send']['submit']['#value'] = $this->t('Confirm Option 1'); } elseif ($selected_value === 'option2') { - $form['actions']['send']['#value'] = t('Confirm Option 2'); + $form['actions']['send']['#value'] = $this->t('Confirm Option 2'); } return $form['additional_fields_wrapper']; } @@ -209,10 +245,12 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { // If there are any form errors, AJAX replace the form. if ($form_state->hasAnyErrors()) { $response->addCommand(new ReplaceCommand('#modal_example_form', $form)); - } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + } + elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->messenger->addMessage($this->t('The email address <b><em>%email</em></b> is not valid.', ['%email' => $email]), 'error'); $response->addCommand(new ReplaceCommand('#modal_example_form', $form)); - } else { + } + else { $query = $form_values['rest_api_authentication_trial_description']; $query_type = 'trial'; @@ -224,7 +262,8 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { '#markup' => $this->t('Your request for a trial module was sent successfully. Please allow us some time and we will send you the trial module as soon as possible.'), ]; $ajax_form = new OpenModalDialogCommand('Thank you!', $message, ['width' => '50%']); - } else { + } + else { $error = [ '#type' => 'item', '#markup' => $this->t('Error submitting the support query. Please send us your query at diff --git a/src/MiniorangeApiAuthSupport.php b/src/MiniorangeApiAuthSupport.php index de50014..c99aefa 100644 --- a/src/MiniorangeApiAuthSupport.php +++ b/src/MiniorangeApiAuthSupport.php @@ -3,6 +3,7 @@ namespace Drupal\rest_api_authentication; use GuzzleHttp\Exception\GuzzleException; +use Drupal\Core\Url; /** * @file @@ -64,7 +65,7 @@ class MiniorangeApiAuthSupport { public function sendSupportQuery() { $modules_info = \Drupal::service('extension.list.module')->getExtensionInfo('rest_api_authentication'); $modules_version = $modules_info['version']; - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); if ($this->plan == 'demo') { $url = MiniorangeApiAuthConstants::BASE_URL . '/moas/api/notify/send'; diff --git a/src/MiniorangeRestAPICustomer.php b/src/MiniorangeRestAPICustomer.php deleted file mode 100644 index 50ae269..0000000 --- a/src/MiniorangeRestAPICustomer.php +++ /dev/null @@ -1,132 +0,0 @@ -<?php - -namespace Drupal\rest_api_authentication; - -/** - * Help to register the customers. - */ -class MiniorangeRestAPICustomer { - /** - * The email of the customer. - * - * @var string - */ - public $email; - /** - * The phone number of the customer. - * - * @var string - */ - public $phone; - /** - * The customer key. - * - * @var string - */ - public $customerKey; - /** - * The transaction ID. - * - * @var string - */ - public $transactionId; - /** - * The password of the customer. - * - * @var string - */ - public $password; - /** - * The OTP token. - * - * @var string - */ - public $otpToken; - /** - * The default customer ID. - * - * @var string - */ - private $defaultCustomerId; - /** - * The default customer API key. - * - * @var string - */ - private $defaultCustomerApiKey; - /** - * Constructor. - */ - - /** - * Constructor. - * - * @param string $email - * The email of the customer. - * @param string $password - * The password of the customer. - */ - public function __construct($email, $password) { - $this->email = $email; - $this->password = $password; - $this->defaultCustomerId = "16555"; - $this->defaultCustomerApiKey = "fFd2XcvTGDemZvbw1bcUesNJWEqKbbUq"; - } - - /** - * Check if customer exists. - */ - public function checkCustomer() { - if (!Utilities::isCurlInstalled()) { - return json_encode([ - "status" => 'CURL_ERROR', - "statusMessage" => - '<a href="' . MiniorangeApiAuthConstants::PHP_CURL . '">PHP cURL extension</a> is not installed or disabled.', - ]); - } - - $url = MiniorangeApiAuthConstants::BASE_URL . '/moas/rest/customer/check-if-exists'; - $email = $this->email; - $fields = ['email' => $email]; - $field_string = json_encode($fields); - $header = ['Content-Type' => 'application/json', 'charset' => 'UTF - 8', 'Authorization' => 'Basic']; - try { - $content = \Drupal::httpClient()->post($url, ['headers' => $header, 'body' => $field_string, 'verify' => FALSE]); - return $content->getBody(); - } - catch (\Exception $exception) { - $error = ['%method' => 'checkCustomer', '%file' => 'customer_setup.php', '%error' => $exception->getMessage()]; - \Drupal::logger('rest_api_authentication')->notice('Error at %method of %file: %error', $error); - return $exception->getMessage(); - } - } - - /** - * Get Customer Keys. - */ - public function getCustomerKeys() { - if (!Utilities::isCurlInstalled()) { - return json_encode([ - "apiKey" => 'CURL_ERROR', - "token" => '<a href="' . MiniorangeApiAuthConstants::PHP_CURL . '">PHP cURL extension</a> is not installed or disabled.', - ]); - } - - $url = MiniorangeApiAuthConstants::BASE_URL . '/moas/rest/customer/key'; - $email = $this->email; - $password = $this->password; - $fields = ['email' => $email, 'password' => $password]; - $field_string = json_encode($fields); - $header = ['Content-Type' => 'application/json', 'charset' => 'UTF - 8', 'Authorization' => 'Basic']; - try { - $content = \Drupal::httpClient()->post($url, ['headers' => $header, 'body' => $field_string, 'verify' => FALSE]); - return $content->getBody(); - } - catch (\Exception $exception) { - $error = ['%method' => 'getCustomerKeys', '%file' => 'customer_setup.php', '%error' => $exception->getMessage()]; - \Drupal::logger('rest_api_authentication')->notice('Error at %method of %file: %error', $error); - return $exception->getMessage(); - } - } - -} diff --git a/src/MoHeadlessIntegration.php b/src/MoHeadlessIntegration.php index dc07e9b..4fba7d1 100644 --- a/src/MoHeadlessIntegration.php +++ b/src/MoHeadlessIntegration.php @@ -2,13 +2,26 @@ namespace Drupal\rest_api_authentication; -use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Markup; -use Drupal\rest_api_authentication\Utilities; +use Drupal\Core\Url; +/** + * This class is for Headless integration. + */ class MoHeadlessIntegration { + /** + * Builds and returns the form for headless integration settings. + * + * @param array $form + * The form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state object. + * + * @return array + * The modified form array. + */ public static function insertForm(array &$form, FormStateInterface $form_state) { $form['markup_library_1'] = [ @@ -26,14 +39,21 @@ class MoHeadlessIntegration { '#group' => 'verticaltabs', ]; - - self::headlessSSOFieldset($form,$form_state); + self::headlessSSOFieldset($form, $form_state); return $form; } - private static function headlessSSOFieldset(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + /** + * Defines the form elements for the Headless SSO fieldset. + * + * @param array $form + * The form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state object. + */ + private static function headlessSsoFieldset(array &$form, FormStateInterface $form_state) { + $base_url = Utilities::getBaseUrl(); $form['headless_sso_details']['headless_sso'] = [ '#markup' => t('<b>Headless SSO (Single Sign On) </b><a href = ":upgradePlan" style="font-size: small" >PREMIUM</a><a style="float: right;" href=":guideUrl" target="_blank" class="button button--small" >setup guide</a>', @@ -43,21 +63,21 @@ class MoHeadlessIntegration { ]), ]; - $form ['headless_sso_details']['headless_sso']['sso_protocol'] = [ + $form['headless_sso_details']['headless_sso']['sso_protocol'] = [ '#prefix' => t('<p style="font-size: small"> This section help you to setup the headless sso with the help of the <a href=":oauthClient" target="_blank">Drupal OAuth Client</a> or <a href=":saml" target="_blank">miniOrange SAML module</a>.</p> <hr>', [ ':oauthClient' => 'https://www.drupal.org/project/miniorange_oauth_client', ':saml' => 'https://www.drupal.org/project/miniorange_saml', - ] ), + ]), ]; $form['headless_sso_details']['headless_sso']['headless_sso_table'] = [ '#type' => 'table', - '#responsive' => TRUE , - '#attributes' => ['style' => 'border-collapse: separate;',], + '#responsive' => TRUE, + '#attributes' => ['style' => 'border-collapse: separate;'], ]; - $configurations = Utilities::getHeadlessTableAttr(); + $configurations = Utilities::getHeadlessTableAttr(); foreach ($configurations as $key => $value) { $row = self::generateHeadlessSooTableRow($key, $value); @@ -68,18 +88,29 @@ class MoHeadlessIntegration { '#type' => 'submit', '#button_type' => 'primary', '#value' => 'Save Settings', - '#disabled' => true, + '#disabled' => TRUE, ]; } + + /** + * Generates a row for the Headless SSO table based on configuration. + * + * @param string $key + * The configuration key. + * @param string $value + * The configuration value. + * + * @return array + * The table row as a renderable array. + */ private static function generateHeadlessSooTableRow(string $key, string $value) { - $config = \Drupal::config('rest_api_authentication'); - $row[$key.$value] = [ - '#markup' => '<div class="container-inline" ><strong>'.$value.'</strong>', + $row[$key . $value] = [ + '#markup' => '<div class="container-inline" ><strong>' . $value . '</strong>', ]; - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); - if($key == 'module'){ + $base_url = Utilities::getBaseUrl(); + if ($key == 'module') { $row[$key] = [ '#type' => 'radios', '#title' => '', @@ -87,26 +118,29 @@ class MoHeadlessIntegration { '#attributes' => [ 'class' => ['container-inline'], ], - '#disabled' => true, + '#disabled' => TRUE, ]; - }else if($key == 'frontend_url'){ + } + elseif ($key == 'frontend_url') { $row[$key] = [ '#type' => 'textfield', '#description' => t('Enter the frontend URL where the user will be redirected after SSO.'), '#attributes' => ['style' => 'width:50%'], - '#disabled' => true, + '#disabled' => TRUE, ]; - }else if( $key == 'get_token_url'){ + } + elseif ($key == 'get_token_url') { $row[$key] = [ - '#markup' => Markup::create('<span id = "'.$key.'">' . $base_url . '/get-token</span> + '#markup' => Markup::create('<span id = "' . $key . '">' . $base_url . 'get-token</span> '), ]; - }else { + } + else { $row[$key] = [ '#type' => 'radios', '#title' => '', - '#states' => ['visible' => [':input[name = "module"]' => ['value' => 0 ], ],], + '#states' => ['visible' => [':input[name = "module"]' => ['value' => 0]]], '#options' => [ 0 => t('Send JWT created by the module'), 1 => t('send JWT received from the OAuth Server'), @@ -114,9 +148,10 @@ class MoHeadlessIntegration { '#attributes' => [ 'class' => ['container-inline'], ], - '#disabled' => true, + '#disabled' => TRUE, ]; } return $row; } + } diff --git a/src/RequestForDemoForm.php b/src/RequestForDemoForm.php index a6a422b..d23f7c7 100644 --- a/src/RequestForDemoForm.php +++ b/src/RequestForDemoForm.php @@ -29,24 +29,24 @@ class RequestForDemoForm { ]; $form['demo']['container_outline']['markup_support_1'] = [ - '#markup' => '<b>SUPPORT/REQUEST FOR DEMO:</b><hr><div class="mo_rest_api_highlight_background_note_1">Want to test our premium module before purchasing? Just send us a request from here and we will send you a 7 day free trial.</div><br>', + '#markup' => '<b>' . t('SUPPORT/REQUEST FOR DEMO:') . '</b><hr><div class="mo_rest_api_highlight_background_note_1">' . t('Want to test our premium module before purchasing? Just send us a request from here and we will send you a 7 day free trial.') . '</div><br>', ]; $form['demo']['container_outline']['rest_api_authentication_email_address'] = [ '#type' => 'textfield', '#id' => 'general_text_field', - '#attributes' => ['placeholder' => 'Enter your Email', 'style' => 'width: 70%'], + '#attributes' => ['placeholder' => t('Enter your Email'), 'style' => 'width: 70%'], ]; $form['demo']['container_outline']['rest_api_authentication_phone_number'] = [ '#type' => 'textfield', '#id' => 'general_text_field', - '#attributes' => ['placeholder' => 'Enter your Phone Number', 'style' => 'width: 70%'], + '#attributes' => ['placeholder' => t('Enter your Phone Number'), 'style' => 'width: 70%'], ]; $form['demo']['container_outline']['rest_api_authentication_demo_query'] = [ '#type' => 'textarea', '#id' => 'general_text_field', - '#attributes' => ['placeholder' => 'Please write your use case requirements here', 'style' => 'width: 70%'], + '#attributes' => ['placeholder' => t('Please write your use case requirements here'), 'style' => 'width: 70%'], ]; $form['demo']['container_outline']['rest_api_authentication_demo_query_submit'] = [ '#type' => 'submit', diff --git a/src/SetupAuthenticationForm.php b/src/SetupAuthenticationForm.php index 08bca0f..5eae1ea 100644 --- a/src/SetupAuthenticationForm.php +++ b/src/SetupAuthenticationForm.php @@ -3,6 +3,7 @@ namespace Drupal\rest_api_authentication; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; /** * Provides the form for setting up authentication methods. @@ -21,7 +22,7 @@ class SetupAuthenticationForm { * The populated form array. */ public static function insertForm(array &$form, FormStateInterface $form_state) { - $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath(); + $base_url = Utilities::getBaseUrl(); $form['markup_library_3'] = [ '#attached' => [ 'library' => [ @@ -64,7 +65,10 @@ class SetupAuthenticationForm { ]; $form['api_auth']['mo_rest_api_authentication_authenticator']['head_text'] = [ - '#markup' => '<table><tr><td class="td-class"><b>Select the authentication method of your choice: </td><td></b><a class="button button--small shift-right" target="_blank" href="https://www.drupal.org/docs/contributed-modules/api-authentication">🕮 Setup Guides</a><a class="button button--small shift-right" target="_blank" href="https://youtube.com/playlist?list=PL2vweZ-PcNpevVNw68h6SYsGQHpGcFa6g&feature=shared">⏵Setup videos</a></td></tr></table>', + '#markup' => '<table><tr><td class="td-class"><b>' . t('Select the authentication method of your choice:') . + '</b></td><td>' . '<a class="button button--small shift-right" target="_blank" href="https://www.drupal.org/docs/contributed-modules/api-authentication">🕮 ' . t('Setup Guides') . '</a>' . + '<a class="button button--small shift-right" target="_blank" href="https://youtube.com/playlist?list=PL2vweZ-PcNpevVNw68h6SYsGQHpGcFa6g&feature=shared">⏵ ' . t('Setup Videos') . '</a>' . + '</td></tr></table>', ]; $oauth_token = $base_url . '/admin/config/people/rest_api_authentication/auth_settings?tab=edit-upgrade-plans'; diff --git a/src/UpgradePlansForm.php b/src/UpgradePlansForm.php index b1a7da1..1aa2b1d 100644 --- a/src/UpgradePlansForm.php +++ b/src/UpgradePlansForm.php @@ -52,18 +52,18 @@ class UpgradePlansForm { <div> <div class="pricing-table class_inline_1"> <div class="pricing-header"> - <p class="pricing-title">Free</p> + <p class="pricing-title">' . t('Free') . '</p> <p class="pricing-rate"><sup>$</sup> 0</p> - <a href="#" disabled="disabled" class="btn-disabled button">Current Plan</a><br><br> + <a href="#" disabled="disabled" class="btn-disabled button button--primary">' . t('Current Plan') . '</a><br><br> </div> <div class="pricing-list"> <ul> - <li>Supports JSON API module</li> - <li>Supports default REST APIs</li> + <li>' . t('Supports JSON API module') . '</li> + <li>' . t('Supports default REST APIs') . '</li> <li>-</li> - <li>API Key Authentication</li> - <li>Basic Authentication</li> + <li>' . t('API Key Authentication') . '</li> + <li>' . t('Basic Authentication') . '</li> <li>-</li> <li>-</li> <li>-</li> @@ -75,36 +75,36 @@ class UpgradePlansForm { <li>-</li> <li>-</li> <li>-</li> - <li>Basic Email Support</li> + <li>' . t('Basic Email Support') . '</li> </ul> </div> </div> <div class="pricing-table class_inline_1"> <div class="pricing-header"> - <p class="pricing-title">Premium</p> + <p class="pricing-title">' . t('Premium') . '</p> <p class="pricing-rate"><sup>$</sup> 399<sup>*</sup></p> - <a href="https://portal.miniorange.com/initializepayment?requestOrigin=drupal_rest_api_authentication_premium_plan" target="_blank" class="button">Upgrade Now</a><br><br> + <a href="https://portal.miniorange.com/initializepayment?requestOrigin=drupal_rest_api_authentication_premium_plan" target="_blank" class="button button--primary">' . t('Upgrade Now') . '</a><br><br> </div> <div class="pricing-list"> <ul> - <li>Supports JSON API module</li> - <li>Supports default REST APIs</li> - <li>Supports restriction of custom APIs</li> - <li>API Key Authentication</li> - <li>Basic Authentication</li> - <li>Access Token Based Authentication</li> - <li>JWT Based Authentication</li> - <li>Authenticate private files and images</li> - <li>Support for multiple authentication methods</li> - <li>3rd Party/External IDP Token Based Authentication</li> - <li>Generate separate API Keys for every user</li> - <li>Custom Authentication Header</li> - <li>Configurable Token Expiry Time</li> - <li>Allow or restrict the custom APIs</li> - <li>IP Address Based Restriction</li> - <li>Role Based Restriction</li> - <li>Premium GoTo Meeting Support</li> + <li>' . t('Supports JSON API module') . '</li> + <li>' . t('Supports default REST APIs') . '</li> + <li>' . t('Supports restriction of custom APIs') . '</li> + <li>' . t('API Key Authentication') . '</li> + <li>' . t('Basic Authentication') . '</li> + <li>' . t('Access Token Based Authentication') . '</li> + <li>' . t('JWT Based Authentication') . '</li> + <li>' . t('Authenticate private files and images') . '</li> + <li>' . t('Support for multiple authentication methods') . '</li> + <li>' . t('3rd Party/External IDP Token Based Authentication') . '</li> + <li>' . t('Generate separate API Keys for every user') . '</li> + <li>' . t('Custom Authentication Header') . '</li> + <li>' . t('Configurable Token Expiry Time') . '</li> + <li>' . t('Allow or restrict the custom APIs') . '</li> + <li>' . t('IP Address Based Restriction') . '</li> + <li>' . t('Role Based Restriction') . '</li> + <li>' . t('Premium GoTo Meeting Support') . '</li> </ul> </div> </div> @@ -116,14 +116,25 @@ class UpgradePlansForm { </section> <!-- Pricing Table Section End --> </body> - </html>', + </html>', ]; $form['upgrade-plans']['upgrade_container_outline']['instr'] = [ - '#markup' => ' - <br> - The above-mentioned cost is applicable for one instance only. If you are planning to use the module on multiple instances, you can check out the bulk purchase discount on our <a href="https://plugins.miniorange.com/drupal-rest-api-authentication#pricing" target="_blank">website</a>. - <br><br><br><b>10 Days Return Policy -</b><br><br> - At miniOrange, we want to ensure that you are 100% happy with your purchase. If the premium module you purchased is not working as advertised and you have attempted to resolve any issues with our support team, which could not get resolved, we will refund the whole amount given that you have a raised a refund request within the first 10 days of the purchase.<br><br>Please email us at <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a> for any queries.', + '#markup' => + '<br>' . t( + 'The above-mentioned cost is applicable for one instance only. If you are planning to use the module on multiple instances, you can check out the bulk purchase discount on our <a href="@url" target="_blank">@website</a>.', + [ + '@url' => 'https://plugins.miniorange.com/drupal-rest-api-authentication#pricing', + '@website' => t('website'), + ] + ) . + '<br><br><br><b>' . t('10 Days Return Policy -') . '</b><br><br>' . + t( + 'At miniOrange, we want to ensure that you are 100% happy with your purchase. If the premium module you purchased is not working as advertised and you have attempted to resolve any issues with our support team, which could not get resolved, we will refund the whole amount given that you have a raised a refund request within the first 10 days of the purchase.' + ) . + '<br><br>' . t( + 'Please email us at <a href="mailto:@email">@email</a> for any queries.', + ['@email' => 'drupalsupport@xecurify.com'] + ), ]; $current_request = \Drupal::service('request_stack')->getCurrentRequest(); $tab = $current_request->query->get('tab'); diff --git a/src/Utilities.php b/src/Utilities.php index 4a114cd..ca713b2 100644 --- a/src/Utilities.php +++ b/src/Utilities.php @@ -8,6 +8,7 @@ namespace Drupal\rest_api_authentication; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\OpenModalDialogCommand; +use Drupal\Core\Url; /** * Has the function which help while authenticate the API requests. @@ -104,9 +105,23 @@ class Utilities { } return empty($content) ? $currentTimeInMillis : $content; } - public static function getHeadlessTableAttr() { - return ['module' => 'Select Module', 'frontend_url' => 'Frontend redirect URL', 'get_token_url' => 'ID Token Endpoint ', 'send_jwt' => 'Select JWT type' ]; + /** + * Returns the configuration attributes for the Headless SSO table. + * + * @return array + * Associative array of configuration keys and descriptions. + */ + public static function getHeadlessTableAttr() { + return [ + 'module' => 'Select Module', + 'frontend_url' => 'Frontend redirect URL', + 'get_token_url' => 'ID Token Endpoint ', + 'send_jwt' => 'Select JWT type', + ]; } + public static function getBaseUrl(){ + return Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(); + } } -- GitLab