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

Commit

Permalink
[SD-148] configure captcha in Tide webform
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao committed Sep 9, 2024
1 parent fedc365 commit 1beaa10
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.captcha_widgets.field_captcha_type
- field.field.taxonomy_term.captcha_widgets.field_site_key
- taxonomy.vocabulary.captcha_widgets
module:
- path
- text
id: taxonomy_term.captcha_widgets.default
targetEntityType: taxonomy_term
bundle: captcha_widgets
mode: default
content:
description:
type: text_textarea
weight: 4
region: content
settings:
rows: 5
placeholder: ''
third_party_settings: { }
field_captcha_type:
type: options_select
weight: 1
region: content
settings: { }
third_party_settings: { }
field_site_key:
type: string_textfield
weight: 3
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 5
region: content
settings: { }
third_party_settings: { }
simple_sitemap:
weight: 10
region: content
settings: { }
third_party_settings: { }
status:
type: boolean_checkbox
weight: 6
region: content
settings:
display_label: true
third_party_settings: { }
hidden: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.captcha_widgets.field_captcha_type
- field.field.taxonomy_term.captcha_widgets.field_site_key
- taxonomy.vocabulary.captcha_widgets
module:
- options
- text
id: taxonomy_term.captcha_widgets.default
targetEntityType: taxonomy_term
bundle: captcha_widgets
mode: default
content:
description:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
field_captcha_type:
type: list_default
label: above
settings: { }
third_party_settings: { }
weight: 2
region: content
field_site_key:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 1
region: content
hidden:
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_captcha_type
- taxonomy.vocabulary.captcha_widgets
module:
- options
id: taxonomy_term.captcha_widgets.field_captcha_type
field_name: field_captcha_type
entity_type: taxonomy_term
bundle: captcha_widgets
label: 'Captcha type'
description: ''
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_site_key
- taxonomy.vocabulary.captcha_widgets
id: taxonomy_term.captcha_widgets.field_site_key
field_name: field_site_key
entity_type: taxonomy_term
bundle: captcha_widgets
label: 'Site key'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
29 changes: 29 additions & 0 deletions config/optional/field.storage.taxonomy_term.field_captcha_type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
langcode: en
status: true
dependencies:
module:
- options
- taxonomy
id: taxonomy_term.field_captcha_type
field_name: field_captcha_type
entity_type: taxonomy_term
type: list_string
settings:
allowed_values:
-
value: google_recaptcha_v3
label: 'Google reCAPTCHA v3'
-
value: google_recaptcha_v2
label: 'Google reCAPTCHA v2'
-
value: cloudfare_turnstile
label: 'Cloudfare Turnstile'
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
20 changes: 20 additions & 0 deletions config/optional/field.storage.taxonomy_term.field_site_key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
id: taxonomy_term.field_site_key
field_name: field_site_key
entity_type: taxonomy_term
type: string
settings:
max_length: 255
case_sensitive: false
is_ascii: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
7 changes: 7 additions & 0 deletions config/optional/taxonomy.vocabulary.captcha_widgets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
name: 'CAPTCHA widgets'
vid: captcha_widgets
description: ''
weight: 0
36 changes: 36 additions & 0 deletions tide_webform.install
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,39 @@ function tide_webform_install() {
TideOperation::installWebformConfig();
TideOperation::accessTextEditorInWebform();
}

/**
* Import configs for Captcha feature.
*/
function tide_webform_update_10004() {
/** @var \Drupal\config_update\ConfigReverter $config_update */
$config_update = \Drupal::service('config_update.config_update');

$config_update_list = [
'taxonomy_vocabulary/captcha_widgets',
'field_storage_config/taxonomy_term.field_site_key',
'field_storage_config/taxonomy_term.field_captcha_type',
'field_config/taxonomy_term.captcha_widgets.field_site_key',
'field_config/taxonomy_term.captcha_widgets.field_captcha_type',
'entity_view_display/taxonomy_term.captcha_widgets.default',
'entity_form_display/taxonomy_term.captcha_widgets.default',
];

foreach ($config_update_list as $config_item) {
[$type, $config_id] = explode('/', $config_item, 2);

try {
$result = $config_update->import($type, $config_id);

if ($result) {
\Drupal::logger('tide_webform')->info("Successfully imported {$type}: {$config_id}");
}
else {
\Drupal::logger('tide_webform')->warning("Import returned false for {$type}: {$config_id}. Config might already exist.");
}
}
catch (\Exception $e) {
\Drupal::logger('tide_webform')->error("Error importing {$type}: {$config_id}. Error: " . $e->getMessage());
}
}
}
Loading

0 comments on commit 1beaa10

Please sign in to comment.