commit b0dbf81fe56926fd8eadabf6e5af02f9486f6794
parent c61b2eaef559777e56aa7aec9a1ea7e20dc2b1c8
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 19 Oct 2025 15:34:58 +0200
DCE
Diffstat:
2 files changed, 5 insertions(+), 102 deletions(-)
diff --git a/src/Form/SubscriptionPricesForm.php b/src/Form/SubscriptionPricesForm.php
@@ -162,7 +162,7 @@ class SubscriptionPricesForm extends ConfigFormBase {
if (!is_numeric($price) || $price < 0) {
$form_state->setErrorByName(
"subscription_prices][{$subscription_id}][{$currency_code}",
- $this->t('Subscription prices must be non-negative numbers.')
+ $this->t('Subscription prices cannot be negative.')
);
}
}
@@ -171,15 +171,16 @@ class SubscriptionPricesForm extends ConfigFormBase {
}
}
+
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
+ $config = $this->config('turnstile.settings');
$subscription_prices = $form_state->getValue('subscription_prices');
- $this->config('turnstile.settings')
- ->set('subscription_prices', $subscription_prices)
- ->save();
+ $config->set('subscription_prices', $subscription_prices);
+ $config->save();
parent::submitForm($form, $form_state);
}
diff --git a/src/Form/TurnstileSettingsForm.php b/src/Form/TurnstileSettingsForm.php
@@ -130,72 +130,6 @@ class TurnstileSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('grant_access_on_error') ?: '',
];
-if (FALSE) {
- // Get subscriptions and currencies from API.
- $subscriptions = $this->apiService->getSubscriptions();
- $currencies = $this->apiService->getCurrencies();
-
- if (empty($subscriptions) || empty($currencies)) {
- $this->messenger()->addWarning($this->t('Unable to load subscriptions or currencies from API. Please check your configuration.'));
- }
-
- $form['subscription_prices'] = [
- '#type' => 'fieldset',
- '#title' => $this->t('Subscription prices'),
- '#description' => $this->t('Set the price for buying each subscription type in different currencies.'),
- '#tree' => TRUE,
- ];
-
- $existing_prices = $config->get('subscription_prices') ?: [];
-
- foreach ($subscriptions as $subscription_id => $subscription) {
- $subscription_label = $subscription['label'] ?? $subscription['name'];
-
- // Skip the %none% case as you can't buy "no subscription"
- if ($subscription_id === '%none%') {
- continue;
- }
-
- $form['subscription_prices'][$subscription_id] = [
- '#type' => 'details',
- '#title' => $subscription_label,
- '#open' => FALSE,
- ];
-
- foreach ($currencies as $currency) {
- $currency_code = $currency['code'] ?? $currency['name'];
- $currency_label = $currency['label'] ?? $currency['code'];
-
- $form['subscription_prices'][$subscription_id][$currency_code] = [
- '#type' => 'number',
- '#title' => $currency_label,
- '#default_value' => $existing_prices[$subscription_id][$currency_code] ?? '',
- '#min' => 0,
- '#step' => $currency['step'] ?? 0.01,
- '#size' => 20,
- '#description' => $this->t('Leave empty to prevent buying the subscription with this currency.'),
- ];
- }
- }
-
-
- if ($this->isBackendConfigured()) {
- $form['subscription_prices_link'] = [
- '#type' => 'item',
- '#title' => $this->t('Subscription Prices'),
- '#markup' => $this->t('<p><a href="@url" class="button">Configure Subscription Prices</a></p>', [
- '@url' => Url::fromRoute('turnstile.subscription_prices')->toString(),
- ]),
- ];
- } else {
- $form['subscription_prices_link'] = [
- '#type' => 'item',
- '#title' => $this->t('Subscription Prices'),
- '#markup' => $this->t('<p>You must configure and save the payment backend settings above before configuring subscription prices.</p>'),
- ];
- }
-}
-
return parent::buildForm($form, $form_state);
}
@@ -299,31 +233,6 @@ if (FALSE) {
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
-if (FALSE) {
- // Validate subscription prices
- $subscription_prices = $form_state->getValue('subscription_prices');
- if (is_array($subscription_prices)) {
- foreach ($subscription_prices as $subscription_id => $currencies) {
- if (is_array($currencies)) {
- foreach ($currencies as $currency_code => $price) {
- // Skip empty values as they are allowed (treated as zero).
- if ($price === '' || $price === NULL) {
- continue;
- }
-
- // Validate that the price is a valid non-negative number.
- if (!is_numeric($price) || $price < 0) {
- $form_state->setErrorByName(
- "subscription_prices[$subscription_id][$currency_code]",
- $this->t('Subscription prices cannot be negative.')
- );
- }
- }
- }
- }
- }
-}
-
// Test the access token and backend URL.
$payment_backend_url = $form_state->getValue('payment_backend_url');
$access_token = $form_state->getValue('access_token');
@@ -443,18 +352,11 @@ if (FALSE) {
$grant_access_on_error = $form_state->getValue('grant_access_on_error');
-if (FALSE) {
- $subscription_prices = $form_state->getValue('subscription_prices');
-}
-
// Save configuration.
$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_access_on_error);
-if (FALSE) {
- $config->set('subscription_prices', $subscription_prices);
-}
$config->save();
parent::submitForm($form, $form_state);