Skip to content

Commit 2a5bc93

Browse files
Support Statamic v4 (#142)
Co-authored-by: Jason Varga <[email protected]>
1 parent 83d4616 commit 2a5bc93

File tree

8 files changed

+63
-28
lines changed

8 files changed

+63
-28
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php: [8.0, 8.1]
16-
laravel: [8.*, 9.*]
15+
php: [8.0, 8.1, 8.2]
16+
laravel: [9.*, 10.*]
1717
dependency-version: [prefer-lowest, prefer-stable]
18+
exclude:
19+
- php: 8.0
20+
laravel: 10.*
1821

1922
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
2023

@@ -29,10 +32,6 @@ jobs:
2932
extension-csv: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
3033
coverage: none
3134

32-
- name: Set PHP 8.1 Testbench
33-
run: composer require "orchestra/testbench ^6.22.0" --no-interaction --no-update
34-
if: matrix.laravel == '8.*' && matrix.php >= 8.1
35-
3635
- name: Install dependencies
3736
run: |
3837
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
},
2525
"require": {
2626
"php": "^8.0",
27-
"statamic/cms": "^3.3.51 || 3.4.*"
27+
"statamic/cms": "^4.0.0"
2828
},
2929
"require-dev": {
3030
"doctrine/dbal": "^3.3",
31-
"orchestra/testbench": "^6.7.0 || ^7.0",
31+
"orchestra/testbench": "^7.0 || ^8.0",
3232
"phpunit/phpunit": "^9.4"
3333
},
3434
"scripts": {
@@ -38,5 +38,7 @@
3838
"allow-plugins": {
3939
"pixelfear/composer-dist-plugin": true
4040
}
41-
}
41+
},
42+
"minimum-stability": "dev",
43+
"prefer-stable": true
4244
}

src/Collections/Collection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static function fromModel(Model $model)
2020
->titleFormats($model->settings['title_formats'] ?? null)
2121
->mount($model->settings['mount'] ?? null)
2222
->dated($model->settings['dated'] ?? null)
23-
->ampable($model->settings['ampable'] ?? null)
2423
->sites($model->settings['sites'] ?? null)
2524
->template($model->settings['template'] ?? null)
2625
->layout($model->settings['layout'] ?? null)
@@ -58,7 +57,6 @@ public static function makeModelFromContract(Contract $source)
5857
'title_formats' => collect($source->titleFormats())->filter(),
5958
'mount' => $source->mount,
6059
'dated' => $source->dated,
61-
'ampable' => $source->ampable,
6260
'sites' => $source->sites,
6361
'template' => $source->template,
6462
'layout' => $source->layout,

src/Collections/CollectionModel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ class CollectionModel extends BaseModel
2020
'settings.revisions' => 'boolean',
2121
'settings.dated' => 'boolean',
2222
'settings.default_publish_state' => 'boolean',
23-
'settings.ampable' => 'boolean',
2423
];
2524
}

src/Commands/ImportBlueprints.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,23 @@ private function importBlueprints()
7272

7373
$contents = YAML::file($path)->parse();
7474
// Ensure sections are ordered correctly.
75-
if (isset($contents['sections']) && is_array($contents['sections'])) {
75+
if (isset($contents['tabs']) && is_array($contents['tabs'])) {
7676
$count = 0;
77-
$contents['sections'] = collect($contents['sections'])
78-
->map(function ($section) use (&$count) {
79-
$section['__count'] = $count++;
77+
$contents['tabs'] = collect($contents['tabs'])
78+
->map(function ($tab) use (&$count) {
79+
$tab['__count'] = $count++;
8080

81-
return $section;
81+
if (isset($tab['sections']) && is_array($tab['sections'])) {
82+
$sectionCount = 0;
83+
$tab['sections'] = collect($tab['sections'])
84+
->map(function ($section) use (&$sectionCount) {
85+
$section['__count'] = $sectionCount++;
86+
87+
return $section;
88+
});
89+
}
90+
91+
return $tab;
8292
})
8393
->toArray();
8494
}

src/Entries/Entry.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ public static function fromModel(Model $model)
1717
->origin($model->origin_id)
1818
->locale($model->site)
1919
->slug($model->slug)
20-
->date($model->date)
2120
->collection($model->collection)
2221
->data($model->data)
2322
->blueprint($model->data['blueprint'] ?? null)
2423
->published($model->published)
2524
->model($model);
2625

26+
if ($model->date && $entry->collection()->dated()) {
27+
$entry->date($model->date);
28+
}
29+
2730
if (config('statamic.system.track_last_update')) {
2831
$entry->set('updated_at', $model->updated_at ?? $model->created_at);
2932
}

src/Fields/BlueprintRepository.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function filesIn($namespace)
8383
return Blink::store(self::BLINK_NAMESPACE_PATHS)->once($namespace ?? 'none', function () use ($namespace) {
8484
$namespace = str_replace('/', '.', $namespace);
8585

86-
if (count(($blueprintModels = BlueprintModel::where('namespace', $namespace)->get())) == 0) {
86+
if (count($blueprintModels = BlueprintModel::where('namespace', $namespace)->get()) == 0) {
8787
return collect();
8888
}
8989

@@ -139,11 +139,21 @@ public function deleteModel($blueprint)
139139
private function addOrderToBlueprintSections($contents)
140140
{
141141
$count = 0;
142-
$contents['sections'] = collect($contents['sections'] ?? [])
143-
->map(function ($section) use (&$count) {
144-
$section['__count'] = $count++;
142+
$contents['tabs'] = collect($contents['tabs'] ?? [])
143+
->map(function ($tab) use (&$count) {
144+
$tab['__count'] = $count++;
145145

146-
return $section;
146+
if (isset($tab['sections']) && is_array($tab['sections'])) {
147+
$sectionCount = 0;
148+
$tab['sections'] = collect($tab['sections'])
149+
->map(function ($section) use (&$sectionCount) {
150+
$section['__count'] = $sectionCount++;
151+
152+
return $section;
153+
});
154+
}
155+
156+
return $tab;
147157
})
148158
->toArray();
149159

@@ -152,12 +162,23 @@ private function addOrderToBlueprintSections($contents)
152162

153163
private function updateOrderFromBlueprintSections($contents)
154164
{
155-
$contents['sections'] = collect($contents['sections'] ?? [])
165+
$contents['tabs'] = collect($contents['tabs'] ?? [])
156166
->sortBy('__count')
157-
->map(function ($section) {
158-
unset($section['__count']);
167+
->map(function ($tab) {
168+
unset($tab['__count']);
169+
170+
if (isset($tab['sections']) && is_array($tab['sections'])) {
171+
$tab['sections'] = collect($tab['sections'])
172+
->sortBy('__count')
173+
->map(function ($section) use (&$sectionCount) {
174+
unset($section['__count']);
175+
176+
return $section;
177+
})
178+
->toArray();
179+
}
159180

160-
return $section;
181+
return $tab;
161182
})
162183
->toArray();
163184

tests/Factories/EntryFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ public function make()
9494
->collection($this->createCollection())
9595
->slug($this->slug)
9696
->data($this->data)
97-
->date($this->date)
9897
->origin($this->origin)
9998
->published($this->published);
10099

100+
if ($this->date) {
101+
$entry->date($this->date);
102+
}
103+
101104
if ($this->id) {
102105
$entry->id($this->id);
103106
}

0 commit comments

Comments
 (0)