Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shifuma opened this issue Sep 14, 2024 · 2 comments
Labels

Comments

@shifuma
Copy link

shifuma commented Sep 14, 2024

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

@brandonkelly
Copy link
Member

Thanks for reporting that! Just fixed for the next release.

To test the fix early, change your craftcms/cms requirement in composer.json to

"craftcms/cms": "5.x-dev as 5.4.4",

@brandonkelly
Copy link
Member

Craft 5.4.5 is out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants