Skip to content

Commit b7f9af7

Browse files
committed
Fix some bugs that occur when setting up a new Craft 6 project
1 parent 8ca83d0 commit b7f9af7

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

routes/actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
// Entry Types
142142
Route::get('entry-types/table-data', [EntryTypesController::class, 'tableData']);
143-
Route::get('entry-types/edit/{entryType}', [EntryTypesController::class, 'edit']);
143+
Route::get('entry-types/edit/{entryType?}', [EntryTypesController::class, 'edit']);
144144
Route::middleware([
145145
RequireAdminChanges::class,
146146
])->group(function () {

src/Http/Controllers/FieldsController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ public function edit(Request $request, ?FieldInterface $field = null, ?int $fiel
7373
{
7474
$fieldId ??= $field->id ?? $request->input('fieldId');
7575

76-
abort_if(is_null($fieldId), 404, 'Field not found');
76+
if (is_null($fieldId)) {
77+
return $this->create();
78+
}
7779

7880
abort_if(is_null($found = $this->fieldsService->getFieldById((int) $fieldId)), 404, 'Field not found');
7981

src/Http/Controllers/Settings/EntryTypesController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ public function create(): CpScreenResponse
8888
]);
8989
}
9090

91-
public function edit(EntryTypeModel $entryType): CpScreenResponse
91+
public function edit(Request $request, ?EntryTypeModel $entryType = null): CpScreenResponse
9292
{
93+
$entryType ??= EntryTypeModel::find($request->input('entryTypeId'));
94+
95+
abort_if(is_null($entryType), 404, 'Entry type not found');
96+
9397
$entryTypeData = $this->entryTypes->getEntryTypeById($entryType->id);
9498

9599
abort_if(is_null($entryTypeData), 404, 'Entry type not found');

yii2-adapter/legacy/services/Categories.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use CraftCms\Cms\Support\Facades\Sites;
2929
use CraftCms\Cms\Support\Facades\Structures;
3030
use CraftCms\Cms\Support\Str;
31+
use CraftCms\Yii2Adapter\Yii2ServiceProvider;
3132
use Illuminate\Database\Query\Builder;
3233
use Illuminate\Support\Collection;
3334
use Illuminate\Support\Facades\DB;
@@ -122,6 +123,12 @@ public function getEditableGroupIds(): array
122123
private function _groups(): MemoizableArray
123124
{
124125
if (!isset($this->_groups)) {
126+
if (!Yii2ServiceProvider::supportsCategories()) {
127+
$this->_groups = new MemoizableArray([]);
128+
129+
return $this->_groups;
130+
}
131+
125132
$groupRecords = CategoryGroupRecord::find()
126133
->orderBy(['name' => SORT_ASC])
127134
->with('structure')

yii2-adapter/src/Yii2ServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function boot(): void
357357
* Load Craft when necessary
358358
*/
359359
spl_autoload_register(function($class) {
360-
if ($class === 'Craft') {
360+
if ($class === 'Craft' || $class === 'Yii') {
361361
app('Craft');
362362
}
363363
});

0 commit comments

Comments
 (0)