Error creating new policy body field

Created on 17 April 2023, about 1 year ago
Updated 14 July 2023, 12 months ago

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.

๐Ÿ› Bug report
Status

Fixed

Version

1.2

Component

User interface

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain JoseCarlosss

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS

    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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain Aranzazu_dru

    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!

  • Status changed to Active about 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS

    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.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    5 pass
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS

    Please can someone confirm if this fixes the problem?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    @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.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS

    @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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    @Adam, Yes sure. Am on to it.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    @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 body policy field.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS

    @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๐Ÿ˜ƒ.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    @Adam, Okay. Thank You.

    • AdamPS โ†’ committed 39716452 on 1.x
      Issue #3354578 by AdamPS, Raveen Thakur: Error creating new policy body...
  • Status changed to Fixed 12 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom AdamPS

    No reply so I'll commit it.

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

Production build 0.69.0 2024