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.

This issue has now been shown to exist across multiple version of Drupal and is not specific to 10.3.3. There is a patch attached that many report applies cleanly and fixes the issue.

Steps to Reproduce

1. Go to Structure > Content Types and click on "Manage Fields" for any content type.
2. Click the "Create new Field" button at the top right, select the "Formatted text" type on the "Add field" form. Next select "Markup" and add a Label.
3. You will now be on the field settings form. Fill out required fields and notice that the "Markup" text area contains the number "1" as shown in the attached screenshot 3473518.basic_page.field_settings.png
4. Fill out the "Markup" field with the content you want shown on the form and click save.
5. Now go to Content > Add Content > Basic Page and note that the Markup is indeed displayed as expected.
6. Now go back to the "Manage Fields" page for this content type and edit the "Markup" field. Notice that unfortunately your beautiful markup has been replaced by the number 1 again.

Issue fork markup-3473518

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

uv516 created an issue. See original summary.

uv516’s picture

Component: User interface » Code

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.

tjhellmann’s picture

StatusFileSize
new722 bytes

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

uv516’s picture

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

alfthecat’s picture

Status: Active » Needs review
goose2000’s picture

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

laceysanderson’s picture

Issue summary: View changes
StatusFileSize
new517.08 KB

Expand bug report to include steps to reproduce the issue and attach screenshot.

laceysanderson’s picture

Version: 2.0.0 » 2.x-dev
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new450.51 KB

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!

anybody’s picture

I can confirm this issue, on it! Please use MRs!

anybody’s picture

Assigned: Unassigned » grevil
Status: Reviewed & tested by the community » Needs review

Please review MR.

grevil’s picture

Assigned: grevil » Unassigned
Status: Needs review » Reviewed & tested by the community

LGTM!

grevil’s picture

Status: Reviewed & tested by the community » Fixed
grevil’s picture

Status: Fixed » Closed (fixed)

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