Problem/Motivation

Can not create body field in new policy system/mailer/policy

Steps to reproduce

Go to system/mailer/policy
Add policy
Add body field

Return AJAX error and i cant add field body.

Comments

JoseCarlosss created an issue. See original summary.

adamps’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

I followed the "steps to reproduce" and it works fine for me. I guess there is something unusual about your website. The next step is for you to provide more detailed steps to reproduce.

aranzazu_dru’s picture

I think that we need more information, maybe the ajax error or something like that to see where is the problem, anyways, I had the same problem when I tried to add the body field(or others in symfony mailer) and get and ajax error.
In my case it was because trying to add the field, Drupal tries to access information that (because is a new field without information) does not exist yet...
I have solved it by modifying the code in the "BodyEmailAdjuster.php" class just like this:

public function settingsForm(array $form, FormStateInterface $form_state) {
if(!empty($this->configuration['content'])){
$content = $this->configuration['content'];
$form['content'] = [
'#title' => $this->t('Content'),
'#type' => 'text_format',
'#default_value' => $content['value'],
'#format' => $content['format'] ?? filter_default_format(),
'#required' => TRUE,
'#rows' => 10,
'#description' => $this->t('Email body. This field may support tokens or Twig template syntax – please check the supplied default policy for possible values.'),
];
}else{
$form['content'] = [
'#title' => $this->t('Content'),
'#type' => 'text_format',
'#default_value' => '',
'#format' => filter_default_format(),
'#required' => TRUE,
'#rows' => 10,
'#description' => $this->t('Email body. This field may support tokens or Twig template syntax – please check the supplied default policy for possible values.'),
];
}
...
return $form;
}

However, you must see if the problem you have is with this class or not by debuggin or something.

I hope it helps you anyways!

adamps’s picture

Status: Postponed (maintainer needs more info) » Active

OK, thanks, I'm convinced - the code is accessing an undefined array key which we shouldn't do. I still can't hit the bug myself, so I guess the warning must be swallowed somehow by AJAX.

The same problem exists for WrapAndConvertEmailAdjuster. The other adjusters are fine as far as I can see.

adamps’s picture

Status: Active » Needs review
StatusFileSize
new2.24 KB
adamps’s picture

Please can someone confirm if this fixes the problem?

raveen_thakur51’s picture

StatusFileSize
new34.91 KB

@AdamPS, I was able to add a body field. I am using Drupal version - 9.5.9, PHP - 8.1 & Composer - 2.6
I am adding a screenshot after adding the body field in add policy. Please review.
And Thank You.

adamps’s picture

@Raveen, thanks. Please can you confirm (a screenshot would be great) that you saw the error without the patch? That's the key here - it needs someone who can see the original bug to confirm that it is fixed.

raveen_thakur51’s picture

@Adam, Yes sure. Am on to it. I'll let you know in a moment.

raveen_thakur51’s picture

@Adam, I wonder, could you please elaborate more on this? Because even without a patch it is working fine. It is allowing to add a new policy body field.

adamps’s picture

@Raveen, yes, it's the same for me. The bug only occurs for a few people, so only those people can confirm that the patch is working. However thanks anyway for your time😃.

raveen_thakur51’s picture

@Adam, Okay. Thank You.

  • AdamPS committed 39716452 on 1.x
    Issue #3354578 by AdamPS, Raveen Thakur: Error creating new policy body...
adamps’s picture

Status: Needs review » Fixed

No reply so I'll commit it.

Status: Fixed » Closed (fixed)

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