Skip to content

[6.x]: TypeError when saving a Structure section with maxLevels set #18809

@ivowk

Description

@ivowk

What happened?

Description

First of all, huge kudos for the move to Laravel. I am really excited about where this is heading.

I ran into a TypeError when saving a Structure section with a maxLevels value. The raw request string is assigned directly to a ?int typed property, while the identical maxAuthors field on the same form already handles this correctly with an is_numeric cast.

Steps to reproduce

  1. Go to Settings → Sections
  2. Create or edit a section of type Structure
  3. Enter any value in the Max Levels field
  4. Save

Expected behavior

The section saves successfully with the maxLevels value stored as an integer.

Actual behavior

TypeError
vendor/craftcms/cms/src/Http/Controllers/Settings/SectionsController.php:179
Cannot assign string to property CraftCms\Cms\Section\Data\Section::$maxLevels of type ?int
// Before
$section->maxLevels = $request->input('maxLevels') ?: null;

// After, mirrors the existing maxAuthors pattern on line 172
$maxLevels = $request->input('maxLevels');
$section->maxLevels = is_numeric($maxLevels) ? (int) $maxLevels : null;

Craft CMS version

6.0.0-alpha.1

PHP version

8.5

Operating system and version

ddev on macOS

Database type and version

mysql 8.4

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions