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

Commit

Permalink
changes based on the feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao committed Sep 20, 2024
1 parent 5a5070c commit 628299a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tide_webform.module
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ function tide_webform_webform_third_party_settings_form_alter(array &$form, Form
$webform = $form_state->getFormObject()->getEntity();
$third_party_settings = $webform->getThirdPartySettings('tide_webform_captcha');
$user_input = $form_state->getUserInput();
$taxonomy_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$captcha_type = NULL;
$allowed_values = [];
try {
Expand All @@ -460,7 +461,9 @@ function tide_webform_webform_third_party_settings_form_alter(array &$form, Form
}
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()]);
\Drupal::logger('tide_webform')
->error('Error loading CAPTCHA type options for webform @webform: @message',
['@webform' => $webform->id(), '@message' => $e->getMessage()]);
return;
}
if (isset($third_party_settings['captcha_type'])) {
Expand All @@ -469,12 +472,12 @@ function tide_webform_webform_third_party_settings_form_alter(array &$form, Form
if (isset($user_input['third_party_settings']['tide_webform_captcha']['captcha_type'])) {
$captcha_type = $user_input['third_party_settings']['tide_webform_captcha']['captcha_type'];
}
$query = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->getQuery()
$query = $taxonomy_storage->getQuery()
->accessCheck(TRUE)
->condition('vid', 'captcha_widgets')
->condition('field_captcha_type', $captcha_type);
$tids = $query->execute();
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple($tids);
$terms = $taxonomy_storage->loadMultiple($tids);
$options = array_map(function (Term $term) {
return $term->label() . ' (' . $term->id() . ')';
}, $terms);
Expand All @@ -488,12 +491,12 @@ function tide_webform_webform_third_party_settings_form_alter(array &$form, Form
$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'),
'#title' => t('Enable captcha'),
];

$form['third_party_settings']['tide_webform_captcha']['captcha_type'] = [
'#type' => 'select',
'#title' => 'Captcha type',
'#title' => t('Captcha type'),
'#options' => [
'all' => '-Select-',
] + $allowed_values,
Expand Down

0 comments on commit 628299a

Please sign in to comment.