Skip to content

Commit

Permalink
General settings readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Jan 14, 2025
1 parent 9b6dc50 commit f6f1dd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/controllers/BaseAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function init(): void
$this->requireAdmin(false);
}

protected function isReadyOnlyScreen(): bool
protected function isReadOnlyScreen(): bool
{
return !Craft::$app->getConfig()->getGeneral()->allowAdminChanges;
}
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class SettingsController extends BaseAdminController
*/
public function actionEdit(): Response
{
$readOnly = $this->isReadOnlyScreen();
return $this->renderTemplate('commerce/settings/general', [
'settings' => Plugin::getInstance()->getSettings(),
'readonly' => $this->isReadyOnlyScreen(),
'readOnly' => $this->isReadOnlyScreen(),
]);
}

Expand Down
21 changes: 15 additions & 6 deletions src/templates/settings/general/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
{% extends "commerce/_layouts/settings" %}

{% set selectedTab = 'settings' %}
{% set fullPageForm = true %}

{% import "_includes/forms" as forms %}

{% from _self import configWarning %}

{% block content %}
{% if readOnly %}
{% set contentNotice = readOnlyNotice() %}
{% endif %}

{% block content %}
<h2>{{ "General Settings"|t('commerce') }}</h2>

<form action="" method="post" accept-charset="UTF-8" data-saveshortcut>
<input type="hidden" name="action" value="commerce/settings/save-settings">
{{ redirectInput('commerce/settings/general') }}
{{ csrfInput() }}

{% if not readOnly %}
{{ actionInput('commerce/settings/save-settings') }}
{{ redirectInput('commerce/settings/general') }}
{% endif %}

<h3>{{ 'Units'|t('commerce') }}</h3>
{{ forms.selectField({
Expand All @@ -24,6 +31,7 @@
options: settings.getWeightUnitsOptions(),
errors: settings.getErrors('weightUnits'),
required: true,
disabled: readOnly,
warning: configWarning('weightUnits', 'commerce'),
}) }}

Expand All @@ -35,6 +43,7 @@
options: settings.getDimensionUnits(),
errors: settings.getErrors('dimensionUnits'),
required: true,
disabled: readOnly,
warning: configWarning('dimensionUnits', 'commerce'),
}) }}

Expand All @@ -50,6 +59,7 @@
required: false,
suggestEnvVars: true,
suggestAliases: true,
disabled: readOnly,
placeholder: "//example.com/subscriptions/updateBillingDetails",
warning: configWarning('updateBillingDetailsUrl', 'commerce'),
}) }}
Expand All @@ -63,11 +73,10 @@
value: settings.defaultView,
options: settings.getDefaultViewOptions(),
errors: settings.getErrors('defaultView'),
disabled: readOnly,
required: true,
warning: configWarning('defaultView', 'commerce'),
}) }}

<input type="submit" class="btn submit" value="{{ 'Save'|t('commerce') }}">
</form>

{% endblock %}

0 comments on commit f6f1dd8

Please sign in to comment.