Skip to content

Repeater admin input uses formatted field value, causing Hanna Code to be replaced on save #2343

Description

@Alfred-Bes

Repeater admin input uses formatted field value, causing Hanna Code to be replaced on save

With the help of AI, I was able to trace what appears to be the cause of this issue: output formatting seems to remain enabled while repeater inputfields are created in the admin.

I found an issue with a multilingual text field inside a Repeater.

Environment

ProcessWire 3.0.255
FieldtypeRepeater
FieldtypeTextLanguage
TextformatterHannaCode

The multilingual text field has TextformatterHannaCode assigned.

Example value:

A [[test]] B [[hanna_test]] C

Where:

[[test]]

is not an existing Hanna Code, and:

[[hanna_test]]

is an existing Hanna Code that outputs:

HANNA-TEST

Actual behaviour

After saving the page, the database still contains the correct raw value:

A [[test]] B [[hanna_test]] C

However, when the repeater item is rendered again in Page Edit, the input field contains:

A [[test]] B HANNA-TEST C

So the existing Hanna Code is already formatted before being placed into the admin input field.

At this point the database is still unchanged.

If the page is saved again, the formatted value is submitted and the database is then changed to:

A [[test]] B HANNA-TEST C

The original Hanna Code tag is therefore permanently lost.

Expected behaviour

Admin input fields should always receive the unformatted/raw value:

A [[test]] B [[hanna_test]] C

Hanna Code should only be rendered for frontend/output formatting.

Cause / workaround

The issue appears to be related to output formatting being enabled on the repeater item when its inputfields are created.

In:

/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.module

the current method is:

protected function getRepeaterItemInputfields(Page $page) {
	return $page->template->fieldgroup
		->getPageInputfields($page, "_repeater{$page->id}");
}

Changing it temporarily to:

protected function getRepeaterItemInputfields(Page $page) {

	$of = $page->of();

	$page->of(false);

	$inputfields = $page->template->fieldgroup
		->getPageInputfields($page, "_repeater{$page->id}");

	$page->of($of);

	return $inputfields;
}

completely fixes the issue.

With this change:

Database: [[hanna_test]]
Admin:    [[hanna_test]]
Frontend: HANNA-TEST

as expected.

So it seems that getPageInputfields() is currently receiving a repeater Page with output formatting enabled, causing textformatters to be applied while populating admin input fields.

I also checked ProcessWire 3.0.259 and the current dev branch, and the relevant code appears to still be unchanged.

This used to work correctly in older ProcessWire versions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions