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-' }) }} - +