Markup data is lost

Created on 11 September 2024, 2 months ago
Updated 18 September 2024, 2 months ago

In Drupal 10.3.3:

I have created a markup field and entered a text in the "Markup" text field. The field is saved.
When I open the field to edit the text, only "1" is written in the field. All my text is gone.
It is the same problem with all markup fields on all my sites.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡°Denmark uv516 Denmark

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

Comments & Activities

  • Issue created by @uv516
  • πŸ‡©πŸ‡°Denmark uv516 Denmark

    I found the error myself and have solved the problem.
    I hope that someone can make a patch and that the Maintainers will fix the bug in an upcoming update.
    The problem uccur in file MarkupItem.php in "\modules\contrib\markup\src\Plugin\Field\FieldType\", function fieldSettingsForm, line 70:

    public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
        $settings = $this->getSettings();
    
        $element['markup'] = [
          '#type'          => 'text_format',
          '#title'         => $this->t('Markup'),
    +      '#default_value' => $settings['markup']['value'] ?? '',
    -      '#default_value' => isset($settings['markup']['value']) ?? '',
          '#format'        => !empty($settings['markup']['format']) ? $settings['markup']['format'] : filter_default_format(),
          '#required'      => TRUE,
          '#rows'          => 15,
          '#description'   => $this->t('The markup to be displayed. Any HTML is legal here, so be careful not to break your page layout.'),
        ];
    
        $element['instructions'] = [
          '#markup' => htmlentities($this->t('This is a special field. It will output the markup below, on the node/edit form for this content type. Consider wrapping any visible output in <div class="form-item"></div> to follow form standards.')),
          '#weight' => -1,
        ];
    
        return $element;
      }

    because isset($settings['markup']['value']) ?? '', returns (boolean) 1 if value is not empty,
    but $settings['markup']['value'] ?? '', will return the field value if value is not empty.

  • πŸ‡ΊπŸ‡ΈUnited States tjhellmann Indianapolis, IN

    I ran into this same issue. The code change in #2 fixed the issue for us. Attaching a patch with the change.

  • πŸ‡©πŸ‡°Denmark uv516 Denmark

    Great! - I hope there will be an update very soon. There must be others besides the two of us who have the same problem?

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat
  • πŸ‡ΊπŸ‡ΈUnited States goose2000

    I will just report, I am on D10.3.5 and this patch applied clean and fixed the issue for me.

    Thank you guys!

    @uv516
    @tjhellmann

  • πŸ‡¨πŸ‡¦Canada laceysanderson

    I can confirm that this issue is still relevant on the development version (commit 517b941f77) on Drupal 11.0.6 on Simplytest.me. See screenshot 3473518.withoutpatchapplied.png

    Manual Testing of the patch

    I then tested the patch in comment #3 on simplytest.me by setting the module version to 2.x-dev, Drupal to 11.0.6 and supplying the patch. In this environment I can confirm that the patch applies cleanly and that when following the steps to reproduce, I no longer see the error. More specifically, when editing an instance of the markup field with this patch the previously saved value of the "Markup" text area is populated. Changing this value and saving, correctly saves the new value. Viewing the "Add Basic Page" form displays the value of the markup field in the form exactly as I expected.

    I also manually tested this in my own local development environment (Drupal 10.4.x-dev; PHP 8.3; PostgreSQL 16 backend; gin admin theme) and it works beautifully!

    Code Review

    1. The changes in the patch address the specific issue reported and only address that issue.
    2. The patch applies cleanly on the most recent development version (commit 517b941f77).
    3. The code change follows coding standards and is both clean and easy to read.

    Based on my manual testing and code review, I believe this patch is ready! Furthermore, since other users have also reported that it applies cleanly in their environments and fixes the issue, I am marking this "Reviewed and tested by the community".
    Hopefully it can be merged soon!

Production build 0.71.5 2024