The website encountered an unexpected error. Please try again later.
Error: Call to a member function id() on null in Drupal\contact\MessageForm->form() (line 149 of core/modules/contact/src/MessageForm.php).

Comments

hop created an issue. See original summary.

chris matthews’s picture

Version: 8.x-1.0 » 8.x-1.x-dev

@hop, can you provide the steps necessary to reproduce this issue?

hop’s picture

  1. admin/structure/types/manage/page/fields/add-field
    • New field: Other
    • Type: Contact form
  2. admin/structure/types/manage/page/display
    • Format: Rendered contact form
  3. node/add/page
    • Form: Personal contact form
    • Save
  4. The website encountered an unexpected error. Please try again later.
    Error: Call to a member function id() on null in Drupal\contact\MessageForm->form() (line 149 of core/modules/contact/src/MessageForm.php).
albertski’s picture

@hop, When viewing the form on the actual contact form page (not your node), do you get an error as well?

hop’s picture

Contact form (URL: /contact and /contact/feedback) is OK. Contact form in node is OK too. Problem is only in Node with field Personal contact form.

albertski’s picture

@hop I was able to replicate this issue. It only happens on the Personal Contact form. When you use a different form instead of the Personal Contact form do you still get the error?

hop’s picture

No, only when I use Personal Contact form.

albertski’s picture

For some reason, if you load the personal contact form it does not have $message->getPersonalRecipient(). I created this issue: #3018881: Can't load personal contact form. For now, I created a patch to not load if personal form but the downside is that it will be confusing to the user because nothing will print out.

albertski’s picture

Rerolling patch.

chris matthews’s picture

Status: Active » Needs review

The patch in #9 applied cleanly to ContactFieldFormatter.php and after going through the steps to reproduce fixes this issue for me. @hop, can you confirm the same?

hop’s picture

The patch #9 is OK, thanks. Can you update "stable release"?

  • albertski committed 1ee2b56 on 8.x-1.x
    Issue #3017452 by albertski: Personal Contact Form
    
albertski’s picture

Status: Needs review » Fixed

Patch has been pushed to dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

w01f’s picture

I can't get this module to work.

  • All permissions and settings are correct.
  • Using the latest 1.x-dev version.
  • Attempting to add to /admin/config/people/accounts/fields

The contact form refuses to show on the user page. Any suggestions greately appreciated!

albertski’s picture

@WOLF are you using a Personal Contact form? If so that may be the issue. I mentioned above the patch only prevents the error but it will be confusing because nothing will print out. Try to create another form. Having said that I never tested this on the user entity but don't think that will cause any issues.

seaneffel’s picture

Confirming #15 that custom contact forms are rendered on the user entity but personal contact forms are not. This would be a superior module for placing contact forms on entities if this little detail worked as implied.