Skip to content

Commit c56af47

Browse files
committed
Merge branch 'develop-patch' into develop-minor
2 parents a99a6f1 + 5178229 commit c56af47

3 files changed

Lines changed: 77 additions & 8 deletions

File tree

src/Cms/PageActions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ public static function create(array $props): Page
455455
// keep the initial storage class
456456
$storage = $page->storage()::class;
457457

458+
// Make sure that the page does not already exist at this point.
459+
// Otherwise, moving the storage to memory storage, might delete
460+
// an existing page before we can even run the checks.
461+
PageRules::create($page);
462+
458463
// make sure that the temporary page is stored in memory
459464
$page->changeStorage(MemoryStorage::class);
460465

src/Panel/File.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,17 @@ protected function imageColor(): string
230230
'xlsx' => 'green-500',
231231
];
232232

233-
return
234-
$extensions[$this->model->extension()] ??
235-
$types[$this->model->type()] ??
236-
parent::imageDefaults()['color'];
233+
if ($color = $extensions[$this->model->extension()] ?? null) {
234+
return $color;
235+
}
236+
237+
$type = $this->model->type();
238+
239+
if ($type && ($color = $types[$type] ?? null)) {
240+
return $color;
241+
}
242+
243+
return parent::imageDefaults()['color'];
237244
}
238245

239246
/**
@@ -273,10 +280,17 @@ protected function imageIcon(): string
273280
'xlsx' => 'table',
274281
];
275282

276-
return
277-
$extensions[$this->model->extension()] ??
278-
$types[$this->model->type()] ??
279-
'file';
283+
if ($icon = $extensions[$this->model->extension()] ?? null) {
284+
return $icon;
285+
}
286+
287+
$type = $this->model->type();
288+
289+
if ($type && ($icon = $types[$type] ?? null)) {
290+
return $icon;
291+
}
292+
293+
return 'file';
280294
}
281295

282296
/**

tests/Panel/FileTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,56 @@ public function testImageStringQuery(): void
384384
$this->assertNotEmpty($image);
385385
}
386386

387+
public function testImageColor(): void
388+
{
389+
$page = new ModelPage(['slug' => 'test']);
390+
$file = new ModelFile([
391+
'filename' => 'something.doc',
392+
'parent' => $page
393+
]);
394+
395+
$this->assertSame('blue-500', $file->panel()->image()['color']);
396+
397+
$file = new ModelFile([
398+
'filename' => 'something.mp4',
399+
'parent' => $page
400+
]);
401+
402+
$this->assertSame('yellow-500', $file->panel()->image()['color']);
403+
404+
$file = new ModelFile([
405+
'filename' => 'something.foo',
406+
'parent' => $page
407+
]);
408+
409+
$this->assertSame('gray-500', $file->panel()->image()['color']);
410+
}
411+
412+
public function testImageIcon(): void
413+
{
414+
$page = new ModelPage(['slug' => 'test']);
415+
$file = new ModelFile([
416+
'filename' => 'something.doc',
417+
'parent' => $page
418+
]);
419+
420+
$this->assertSame('pen', $file->panel()->image()['icon']);
421+
422+
$file = new ModelFile([
423+
'filename' => 'something.mp4',
424+
'parent' => $page
425+
]);
426+
427+
$this->assertSame('video', $file->panel()->image()['icon']);
428+
429+
$file = new ModelFile([
430+
'filename' => 'something.foo',
431+
'parent' => $page
432+
]);
433+
434+
$this->assertSame('file', $file->panel()->image()['icon']);
435+
}
436+
387437
public function testIsFocusable(): void
388438
{
389439
$this->app->clone([

0 commit comments

Comments
 (0)