Skip to content

Commit

Permalink
show read-only settings when allowAdminChanges is false
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Feb 6, 2025
1 parent 651cd15 commit abf4f57
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prefer-stable": true,
"require": {
"php": "^8.2",
"craftcms/cms": "^5.0.0-beta.2",
"craftcms/cms": "^5.6.0",
"cakephp/utility": "^5.0.0",
"jakeasmith/http_build_url": "^1.0",
"nesbot/carbon": "^2.10|^3.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public static function config(): array
public bool $hasCpSettings = true;
public bool $hasCpSection = true;

/**
* @inheritdoc
*/
public bool $hasReadOnlyCpSettings = true;

/**
* @var Queue|array|string
* @since 4.5.0
Expand Down Expand Up @@ -108,6 +113,14 @@ public function getSettingsResponse(): mixed
return Craft::$app->controller->redirect(UrlHelper::cpUrl('feed-me/settings'));
}

/**
* @inheritdoc
*/
public function getReadOnlySettingsResponse(): mixed
{
return Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('feed-me/settings'));
}

public function getPluginName(): string
{
return Craft::t('feed-me', $this->getSettings()->pluginName);
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ class BaseController extends Controller
*/
public function actionSettings(): Response
{
$this->requireAdmin();
$this->requireAdmin(false);

$settings = Plugin::$plugin->getSettings();

return $this->renderTemplate('feed-me/settings/general', [
'settings' => $settings,
'readOnly' => !Craft::$app->getConfig()->getGeneral()->allowAdminChanges,
]);
}

Expand Down
12 changes: 10 additions & 2 deletions src/templates/settings/general.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{% requireAdmin %}
{% requireAdmin false %}

{% extends 'feed-me/_layouts/settings' %}

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

{% set fullPageForm = true %}
{% set readOnly = readOnly ?? false %}
{% set fullPageForm = not readOnly %}

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

{% block content %}
<input type="hidden" name="action" value="plugins/save-plugin-settings">
Expand All @@ -20,6 +25,7 @@
first: true,
autofocus: true,
instructions: 'Plugin name for the end user.'|t('feed-me'),
disabled: readOnly,
}) }}

{{ forms.textField({
Expand All @@ -28,6 +34,7 @@
label: 'Cache Duration'|t('feed-me'),
value: settings.cache,
instructions: 'Cache duration (in seconds) to cache requests. Note: this only affects calls using the template tag - requests are never cached when triggering directly via the CP.'|t('feed-me'),
disabled: readOnly,
}) }}

<hr>
Expand All @@ -45,6 +52,7 @@
},
values: settings.enabledTabs,
instructions: 'Choose which tabs you would like to be shown.'|t('feed-me'),
disabled: readOnly,
}) }}

{% endnamespace %}
Expand Down
2 changes: 1 addition & 1 deletion src/web/twig/variables/FeedMeVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getTabs(): array
'utilities' => ['label' => Craft::t('feed-me', 'Utilities'), 'url' => UrlHelper::cpUrl('feed-me/utilities')],
];

if (Craft::$app->getUser()->getIsAdmin() && Craft::$app->getConfig()->getGeneral()->allowAdminChanges) {
if (Craft::$app->getUser()->getIsAdmin()) {
$tabs['settings'] = ['label' => Craft::t('feed-me', 'Settings'), 'url' => UrlHelper::cpUrl('feed-me/settings')];
}

Expand Down

0 comments on commit abf4f57

Please sign in to comment.