diff --git a/src/Fs.php b/src/Fs.php index 97ad6f5..5910bf0 100644 --- a/src/Fs.php +++ b/src/Fs.php @@ -24,6 +24,7 @@ use League\Flysystem\FilesystemAdapter; use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter; use League\Flysystem\GoogleCloudStorage\PortableVisibilityHandler; +use League\Flysystem\Visibility; /** * Class Fs @@ -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 */ @@ -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 */ @@ -316,4 +337,9 @@ private static function _buildConfigArray(string $projectId, string $keyFileCont return $config; } + + protected function visibility(): string + { + return $this->visibility ?? parent::visibility(); + } } diff --git a/src/templates/fsSettings.html b/src/templates/fsSettings.html index 5289a44..66a8b5c 100644 --- a/src/templates/fsSettings.html +++ b/src/templates/fsSettings.html @@ -39,7 +39,7 @@ toggle: true, targetPrefix: '.bsm-' }) }} - +
{{ forms.select({ id: 'bucket', @@ -56,7 +56,7 @@
- +
{{ forms.autosuggest({ label: "Bucket"|t('google-cloud'), @@ -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") %}