turnstile

Drupal paywall plugin
Log | Files | Refs | README | LICENSE

commit b3817fce50285914336baa938bd18247fcf4b5f7
parent 8e3a77bd2c1a9982692b42091ebf6d022a8f1c4e
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  2 Oct 2025 23:30:02 +0200

-fix typo, try to add TalerPriceListFormat validation

Diffstat:
Msrc/Form/TurnstileSettingsForm.php | 18+++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/Form/TurnstileSettingsForm.php b/src/Form/TurnstileSettingsForm.php @@ -2,6 +2,7 @@ namespace Drupal\turnstile\Form; +use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Config\ConfigFactoryInterface; @@ -280,7 +281,7 @@ class TurnstileSettingsForm extends ConfigFormBase { $config->set('enabled_content_types', $new_enabled_types); $config->set('payment_backend_url', $payment_backend_url); $config->set('access_token', $access_token); - $config->set('grant_access_on_error', $grant_on_error); + $config->set('grant_access_on_error', $grant_access_on_error); $config->save(); parent::submitForm($form, $form_state); @@ -322,6 +323,13 @@ class TurnstileSettingsForm extends ConfigFormBase { // Check if field already exists for this bundle. $existing_field = FieldConfig::loadByName('node', $bundle, 'field_price'); if ($existing_field) { + // If field exists, still ensure constraint is applied as we added that logic later. + $constraints = $existing_field->getConstraints(); + if (!isset($constraints['TalerPriceListFormat'])) { + $constraints['TalerPriceListFormat'] = []; + $existing_field->set('constraints', $constraints); + $existing_field->save(); + } continue; } @@ -330,13 +338,13 @@ class TurnstileSettingsForm extends ConfigFormBase { 'field_storage' => $field_storage, 'bundle' => $bundle, 'label' => 'Price', - 'description' => 'Price for accessing this content', + 'description' => 'Price for accessing this content (e.g., "EUR:5" or "USD:5,CHF:3.50" to support payment in multiple currencies)', 'required' => FALSE, ]); + // This adds the PriceFormatConstraintValidator to the field. + $field_config->setConstraints(['TalerPriceListFormat' => []]); $field_config->save(); - // FIXME: how can we do input validation on the amount on submission and/or in JS in the browser? - // Add to form display. $form_display = EntityFormDisplay::load('node.' . $bundle . '.default'); if ($form_display) { @@ -345,7 +353,7 @@ class TurnstileSettingsForm extends ConfigFormBase { 'weight' => 10, 'settings' => [ 'size' => 60, - 'placeholder' => '', + 'placeholder' => 'e.g., EUR:1 or USD:5,CHF:3.50', ], ]); $form_display->save();