Skip to content

[5.x]: Attempt to read property "type" on null when editing Matrix entries on front-end #15737

@shifuma

Description

@shifuma

What happened?

Description

I'm trying to create a front-end entry edit form, but getting Attempt to read property "type" on null.

Steps to reproduce

  1. Use the example entry form as a basis to create a form to edit a Matrix entry
{% set entry = craft.entries().id(1).one() %}

<form method="post" accept-charset="UTF-8">
  {{ csrfInput() }}
  {{ actionInput('entries/save-entry') }}

  {# {{ hiddenInput('sectionId', entry.sectionId) }} -- this is the problem as Matrix entries don't have a section #}
  {{ hiddenInput('typeId', entry.typeId) }}
  {{ hiddenInput('entryId', entry.id) }}
  {{ hiddenInput('enabled', true) }}

  <label for="title">Title</label>
  {{ input('text', 'title', entry.title, {id: 'title',}) }}
  {{ _self.errorList(entry.getErrors('title')) }}

  <button type="submit">Publish</button>
</form>

Expected behavior

Able to save a Matrix entry like regular entries on the front-end.

Actual behavior

Because Matrix entries don't have a section you get this error: yii\base\ErrorException: Attempt to read property "type" on null in /var/www/html/packages/cms/src/controllers/EntriesController.php:252

if (
$entry->id &&
!$duplicate &&
!in_array($currentUser->id, $entry->getAuthorIds(), true) &&
$section->type !== Section::TYPE_SINGLE &&
$entry->enabled
) {


I've tried adding:

{{ hiddenInput('fieldId', 1) }}
{{ hiddenInput('ownerId', entry.ownerId)}}

As per #15345 but that doesn't help. Is there something else I need to add or is this a bug?

Craft CMS version

5.4.3

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions