Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

[SD-148] configure captcha in Tide webform #111

Merged

Conversation

vincent-gao
Copy link
Contributor

@vincent-gao vincent-gao commented Sep 9, 2024

Jira

https://digital-vic.atlassian.net/browse/SD-148

Changes

Integrate tide_webform_captcha settings into webforms to allow each form to configure its own captcha types.

Related PRs

@vincent-gao vincent-gao force-pushed the feature/SD-148-Add-ability-to-configure-captcha branch 12 times, most recently from 31e1eda to 4660398 Compare September 11, 2024 05:56
@vincent-gao vincent-gao self-assigned this Sep 11, 2024
@vincent-gao vincent-gao force-pushed the feature/SD-148-Add-ability-to-configure-captcha branch from 4660398 to be5a3a1 Compare September 11, 2024 07:07
@vincent-gao
Copy link
Contributor Author

The test failed is due to https://github.com/dpc-sdp/dev-tools/blob/master/tests/behat/bootstrap/TideCommonTrait.php#L138 is surprisingly not compatible with Claro

@vincent-gao vincent-gao force-pushed the feature/SD-148-Add-ability-to-configure-captcha branch from c10fabe to 5a5070c Compare September 12, 2024 00:11
Copy link
Contributor

@MdNadimHossain MdNadimHossain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincent-gao some minor fixes would be good. Let me know if the comments make sense.

}
catch (\Exception $e) {
\Drupal::messenger()->addWarning('Unable to load CAPTCHA type options. Please contact the site administrator.');
\Drupal::logger('tide_webform')->error('Error loading CAPTCHA type options: @message', ['@message' => $e->getMessage()]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this logger include the webform id as well for better debugging when looking into the logs. May be something like this -
\Drupal::logger('tide_webform')->error('Error loading CAPTCHA type options for webform @webform: @message', ['@webform' => $webform->id(), '@message' => $e->getMessage()]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed. thanks.

$captcha_type = NULL;
$allowed_values = [];
try {
$field_definition = \Drupal::entityTypeManager()->getStorage('field_storage_config')->load('taxonomy_term.field_captcha_type');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refactoring these calls to reduce repeated service lookups. It is been used 4 times in this function. May be define it in a local var and use it to avoid this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @MdNadimHossain , Could you clarify what you mean by "4 times" in this function? I’m unable to find any others. There are 2 other similar services using \Drupal::entityTypeManager()->getStorage('taxonomy_term'), but they retrieve the taxonomy_term storage, not the field_storage_config storage.

I’ve updated the other two to use a variable like this:
$taxonomy_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry, my bad. I meant the call for entityTypeManager()
so something like this -
$entity_manager = \Drupal::entityTypeManager(); $field_definition = $entity_manager->getStorage('field_storage_config')->load('taxonomy_term.field_captcha_type');


$form['third_party_settings']['tide_webform_captcha']['captcha_type'] = [
'#type' => 'select',
'#title' => 'Captcha type',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use t()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed. thanks.

$form['third_party_settings']['tide_webform_captcha']['enable_captcha'] = [
'#type' => 'checkbox',
'#default_value' => !empty($third_party_settings['enable_captcha']) ? $third_party_settings['enable_captcha'] : NULL,
'#title' => ('Enable captcha'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use t()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed. thanks.

@vincent-gao vincent-gao force-pushed the feature/SD-148-Add-ability-to-configure-captcha branch from b519fea to 628299a Compare September 20, 2024 04:21
@vincent-gao
Copy link
Contributor Author

hey @MdNadimHossain , thanks for the CR, I’ve made some updates based on your feedback. please take a look.

Copy link
Contributor

@MdNadimHossain MdNadimHossain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @vincent-gao
LGTM, resolve the conflicts before merging

try the test patch

changes based on the feedbacks
@vincent-gao vincent-gao force-pushed the feature/SD-148-Add-ability-to-configure-captcha branch from 628299a to f9d29d2 Compare September 24, 2024 22:33
@vincent-gao vincent-gao merged commit 7935351 into develop Sep 24, 2024
3 of 7 checks passed
@vincent-gao vincent-gao deleted the feature/SD-148-Add-ability-to-configure-captcha branch September 24, 2024 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants