diff --git a/administrator/components/com_fields/src/Helper/FieldsHelper.php b/administrator/components/com_fields/src/Helper/FieldsHelper.php index f6afbd77637f5..f2c14a680d2ef 100644 --- a/administrator/components/com_fields/src/Helper/FieldsHelper.php +++ b/administrator/components/com_fields/src/Helper/FieldsHelper.php @@ -176,6 +176,8 @@ function ($f) { $new = []; + $render = array(); + foreach ($fields as $key => $original) { /* * Doing a clone, otherwise fields for different items will @@ -207,24 +209,39 @@ function ($f) { */ Factory::getApplication()->triggerEvent('onCustomFieldsBeforePrepareField', [$context, $item, &$field]); - // Gathering the value for the field - $value = Factory::getApplication()->triggerEvent('onCustomFieldsPrepareField', [$context, $item, &$field]); + $render[$key] = $field; + } - if (is_array($value)) { - $value = implode(' ', $value); - } + $new[$key] = $field; + } - /* - * On after field render - * Event allows plugins to modify the output of the prepared field - */ - Factory::getApplication()->triggerEvent('onCustomFieldsAfterPrepareField', [$context, $item, $field, &$value]); + $contents = []; + + foreach ($render as $key => &$field) { + // Gathering the value for the field + $value = Factory::getApplication()->triggerEvent('onCustomFieldsPrepareField', array($context, $item, &$field)); - // Assign the value - $field->value = $value; + if (is_array($value)) { + $value = implode(' ', $value); } - $new[$key] = $field; + $contents[$key] = $value; + } + + foreach ($render as $key => &$field) { + $value = $contents[$key]; + + /* + * On after field render + * Event allows plugins to modify the output of the prepared field + */ + Factory::getApplication()->triggerEvent('onCustomFieldsAfterPrepareField', array($context, $item, $field, &$value)); + + // Assign the value + $field->value = $value; + + // Assign the render value + $field->content = &$field->value; } $fields = $new;