Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1129 fs url fields part of fs settings #13224

Merged
merged 7 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
- Added `craft\base\ElementInterface::setDirtyFields()`.
- Added `craft\base\ElementInterface::setFieldValueFromRequest()`. ([#12935](https://github.com/craftcms/cms/issues/12935))
- Added `craft\base\FieldInterface::normalizeValueFromRequest()`. ([#12935](https://github.com/craftcms/cms/issues/12935))
- Added `craft\base\FsInterface::getShowHasUrlSetting()`. ([#13224](https://github.com/craftcms/cms/pull/13224))
- Added `craft\base\FsInterface::getShowUrlSetting()`. ([#13224](https://github.com/craftcms/cms/pull/13224))
- Added `craft\base\FsTrait::$showHasUrlSetting`. ([#13224](https://github.com/craftcms/cms/pull/13224))
- Added `craft\base\FsTrait::$showUrlSetting`. ([#13224](https://github.com/craftcms/cms/pull/13224))
- Added `craft\helpers\StringHelper::escapeShortcodes()`. ([#12935](https://github.com/craftcms/cms/issues/12935))
- Added `craft\helpers\StringHelper::unescapeShortcodes()`. ([#12935](https://github.com/craftcms/cms/issues/12935))
- Added `craft\web\CpScreenResponseBehavior::$pageSidebar`, `pageSidebar()`, and `pageSidebarTemplate()`. ([#13019](https://github.com/craftcms/cms/pull/13019), [#12795](https://github.com/craftcms/cms/issues/12795))
Expand Down
16 changes: 16 additions & 0 deletions src/base/Fs.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public function attributeLabels(): array
];
}

/**
* @inheritdoc
*/
public function getShowHasUrlSetting(): bool
{
return static::$showHasUrlSetting;
}

/**
* @inheritdoc
*/
public function getShowUrlSetting(): bool
{
return static::$showUrlSetting;
}

/**
* @inheritdoc
*/
Expand Down
15 changes: 15 additions & 0 deletions src/base/FsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@
*/
interface FsInterface extends BaseFsInterface, SavableComponentInterface
{
/**
* Returns whether the “Files in this filesystem have public URLs” setting should be shown.
*
* @return bool
* @since 4.5.0
*/
public function getShowHasUrlSetting(): bool;

/**
* Returns whether the “Base URL” setting should be shown.
*
* @return bool
* @since 4.5.0
*/
public function getShowUrlSetting(): bool;
}
12 changes: 12 additions & 0 deletions src/base/FsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
*/
trait FsTrait
{
/**
* @var bool Whether the “Files in this filesystem have public URLs” setting should be shown.
* @since 4.5.0
*/
protected static bool $showHasUrlSetting = true;

/**
* @var bool Whether the “Base URL” setting should be shown.
* @since 4.5.0
*/
protected static bool $showUrlSetting = true;

/**
* @var string|null Name
*/
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/FsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ public function actionSave(): ?YiiResponse
'name' => $this->request->getBodyParam('name'),
'handle' => $this->request->getBodyParam('handle'),
'oldHandle' => $this->request->getBodyParam('oldHandle'),
'hasUrls' => (bool)$this->request->getBodyParam('hasUrls'),
'url' => $this->request->getBodyParam('url'),
'settings' => $this->request->getBodyParam("types.$type"),
]);

Expand Down
14 changes: 11 additions & 3 deletions src/services/Fs.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ public function __serialize(): array
*/
public function createFilesystemConfig(FsInterface $fs): array
{
return [
$config = [
'name' => $fs->name,
'type' => get_class($fs),
'hasUrls' => $fs->hasUrls,
'url' => $fs->url,
'settings' => ProjectConfigHelper::packAssociativeArrays($fs->getSettings()),
];

if ($fs->getShowHasUrlSetting()) {
$config['hasUrls'] = $fs->hasUrls;
}

if ($fs->getShowUrlSetting()) {
$config['url'] = $fs->url;
}

return $config;
}

/**
Expand Down
57 changes: 34 additions & 23 deletions src/templates/settings/filesystems/_edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,6 @@
required: true,
}) }}

{{ forms.lightswitchField({
label: 'Files in this filesystem have public URLs'|t('app'),
name: 'hasUrls',
on: filesystem.hasUrls,
toggle: "url-field"
}) }}

<div id="url-field" class="{% if not filesystem.hasUrls %}hidden{% endif %}">
{{ forms.autosuggestField({
label: "Base URL"|t('app'),
instructions: "The base URL to the files in this filesystem."|t('app'),
id: 'url',
class: ['ltr', 'fs-url'],
name: 'url',
suggestEnvVars: true,
suggestAliases: true,
value: (filesystem is defined ? filesystem.url : null),
errors: (filesystem is defined ? filesystem.getErrors('url') : null),
required: true,
placeholder: "//example.com/path/to/folder"
}) }}
</div>

<hr>

{% if fsOptions|length %}
Expand All @@ -69,8 +46,10 @@
<div id="{{ fsType|id }}"{% if not isCurrent %} class="hidden"{% endif %}>
{% namespace 'types['~fsType~']' %}
{% if isCurrent %}
{{ _self.fsUrlFields(filesystem) }}
{{ filesystem.getSettingsHtml()|raw }}
{% else %}
{{ _self.fsUrlFields(fsInstances[fsType]) }}
{{ fsInstances[fsType].getSettingsHtml()|raw }}
{% endif %}
{% endnamespace %}
Expand All @@ -83,3 +62,35 @@
new Craft.HandleGenerator("#{{ 'name'|namespaceInputId }}", "#{{ 'handle'|namespaceInputId }}");
{% endjs %}
{% endif %}


{% macro fsUrlFields(filesystem) %}
{% if filesystem.getShowHasUrlSetting() %}
{{ forms.lightswitchField({
label: 'Files in this filesystem have public URLs'|t('app'),
name: 'hasUrls',
on: filesystem.hasUrls,
toggle: filesystem.getShowUrlSetting() ? "url-field" : null
}) }}
{% endif %}

{% if filesystem.getShowUrlSetting() %}
<div id="url-field" class="{% if not filesystem.hasUrls %}hidden{% endif %}">
{{ forms.autosuggestField({
label: "Base URL"|t('app'),
instructions: "The base URL to the files in this filesystem."|t('app'),
id: 'url',
class: ['ltr', 'fs-url'],
name: 'url',
suggestEnvVars: true,
suggestAliases: true,
value: (filesystem is defined ? filesystem.url : null),
errors: (filesystem is defined ? filesystem.getErrors('url') : null),
required: true,
placeholder: "//example.com/path/to/folder"
}) }}
</div>
{% endif %}

<hr />
{% endmacro %}