The str_replace function in getExtraFieldComponentId may cause the extra field to not load correctly

Created on 20 November 2023, over 1 year ago
Updated 6 December 2023, over 1 year ago

Problem/Motivation

The line $field_id = str_replace('extra_field_', '', $field_id); causes my extra field to not load correctly because the str_replace function removes "extra_field" from my id.
For example:
If I have an id defined as follows: title_extra_field_display, the above line will replace "extra_field" with "", so the result would be "title_display".
In the next line : return 'extra_field_' . $field_id;
The returned result is: extra_field_title_display.
This means that when searching for a match, the result would be null, because the field id returned by the getExtraFieldComponentId() function does not match the id of my extra field custom "title_extra_field_display", which in this case appears in the node as extra_field_title_extra_field_display.

Steps to reproduce

Proposed resolution

As a workaround, you could modify the line using the preg_replace function to simply remove the prefix from the $field_id variable.

$field_id = preg_replace('/^extra_field_/', '', $field_id);

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇪🇸Spain Bryan Toapanta

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

Comments & Activities

Production build 0.71.5 2024