added a sparkbooth section to gallery form, connection details reside there now.
This commit is contained in:
@@ -59,6 +59,7 @@ class GalleryResource extends Resource
|
||||
public static function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data = self::mutatePassword($data);
|
||||
$data = self::mutateSparkbooth($data, true);
|
||||
$data['slug'] = $data['slug'] ?: Str::uuid()->toString();
|
||||
|
||||
return $data;
|
||||
@@ -67,6 +68,7 @@ class GalleryResource extends Resource
|
||||
public static function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data = self::mutatePassword($data);
|
||||
$data = self::mutateSparkbooth($data);
|
||||
$data['slug'] = $data['slug'] ?: Str::uuid()->toString();
|
||||
|
||||
return $data;
|
||||
@@ -83,4 +85,24 @@ class GalleryResource extends Resource
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private static function mutateSparkbooth(array $data, bool $isCreate = false): array
|
||||
{
|
||||
if (array_key_exists('sparkbooth_username', $data)) {
|
||||
$data['sparkbooth_username'] = $data['sparkbooth_username']
|
||||
? Str::of($data['sparkbooth_username'])->lower()->trim()->value()
|
||||
: null;
|
||||
}
|
||||
|
||||
$password = $data['sparkbooth_password'] ?? null;
|
||||
unset($data['sparkbooth_password']);
|
||||
|
||||
if (! empty($password)) {
|
||||
$data['sparkbooth_password'] = $password;
|
||||
} elseif ($isCreate && empty($password)) {
|
||||
$data['sparkbooth_password'] = Str::random(24);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user