Skip to content
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
28 changes: 27 additions & 1 deletion src/Fs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter;
use League\Flysystem\GoogleCloudStorage\PortableVisibilityHandler;
use League\Flysystem\Visibility;

/**
* Class Fs
Expand Down Expand Up @@ -73,6 +74,12 @@ public static function displayName(): string
*/
public string $bucketSelectionMode = 'choose';

/**
* @var ?string Default object visibility (null, 'public', 'private')
* If null, visibility will be determined by self::$hasUrls
*/
public ?string $visibility = null;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -112,10 +119,24 @@ public function rules(): array
{
$rules = parent::rules();
$rules[] = [['bucket', 'projectId'], 'required'];

$rules[] = [
['visibility'],
'in',
'range' => array_keys($this->getVisibilityOptions()),
'strict' => true,
];
return $rules;
}

public function getVisibilityOptions(): array
{
return [
null => Craft::t('google-cloud', 'Automatic'),
Visibility::PUBLIC => Craft::t('google-cloud', 'Public'),
Visibility::PRIVATE => Craft::t('google-cloud', 'Private'),
];
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -316,4 +337,9 @@ private static function _buildConfigArray(string $projectId, string $keyFileCont

return $config;
}

protected function visibility(): string
{
return $this->visibility ?? parent::visibility();
}
}
17 changes: 14 additions & 3 deletions src/templates/fsSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
toggle: true,
targetPrefix: '.bsm-'
}) }}

<div class="bsm-choose{% if fs.bucketSelectionMode == 'manual' %} hidden{% endif %}">
{{ forms.select({
id: 'bucket',
Expand All @@ -56,7 +56,7 @@
<div class="bsm-choose{% if fs.bucketSelectionMode == 'manual' %} hidden{% endif %}">
<div class="spinner hidden"></div>
</div>

<div class="bsm-manual{% if fs.bucketSelectionMode == 'choose' %} hidden{% endif %} flex-grow">
{{ forms.autosuggest({
label: "Bucket"|t('google-cloud'),
Expand Down Expand Up @@ -120,8 +120,19 @@

{{ forms.field({
label: "Cache Duration"|t('google-cloud'),
instructions: "The Cache-Control duration that assets should be uploaded to the cloud with.",
instructions: 'The Cache-Control duration that assets should be uploaded with.'|t('google-cloud'),
id: 'cacheDuration',
}, cacheInput) }}

{{ forms.selectField({
label: 'Visibility'|t('google-cloud'),
instructions: 'The default visibility that assets should be uploaded with.'|t('google-cloud'),
id: 'visibility',
name: 'visibility',
errors: fs.getErrors('visibility'),
value: fs.visibility,
options: fs.getVisibilityOptions(),
tip: "If automatic, the value will be determined by whether this filesystem has public URLs."
}) }}

{% do view.registerAssetBundle("craft\\googlecloud\\GoogleCloudBundle") %}