Fix the Warning: Undefined array key "modal" in Drupal\email_contact\Form\ContactForm->buildForm() (line 77 of ContactForm.php)

Created on 23 January 2023, almost 2 years ago

Problem/Motivation

I got this error trying to access my page with contact us: (Entire log attached in log.txt β†’ )

Warning: Undefined array key "modal" in Drupal\email_contact\Form\ContactForm->buildForm() (line 77 of modules/contrib/email_contact/src/Form/ContactForm.php).
Drupal\email_contact\Form\ContactForm->buildForm(Array, Object)

Steps to reproduce

  1. Enable the project
  2. Create a node with content type "page" and fill the email
  3. Create the node
  4. Go to content type simple page and add a field "email" with type of email as well
  5. Go to mange display and put the email with "Format" as "Email contact inline"
  6. Edit the node created previously and fill the email
  7. Open the node as anonymous user

The error will be displayed

Proposed resolution

This error is happening because on "ContactForm" class there is a method "buildForm" where is verifying if there is field "modal", but with a simple verification if ($this->field_settings['modal']) { the problem is that If the key "modal" doesn't exists the warning will be displayed in the log

To solve that I just put better verification with empty function, it'll verify if the array key "modal" exists, and if is populated.

It solved the issue. The PR is ready to be merged with the fix

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil renatog Campinas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024