[5.4] Prevent custom fields from overriding article properties in com_content API (#47301)#47304
[5.4] Prevent custom fields from overriding article properties in com_content API (#47301)#47304narang24 wants to merge 5 commits intojoomla:5.4-devfrom
Conversation
…y in API response
|
but in this way the custom field is not rendered |
|
Thank you for the feedback @alikon This change was implemented to address the behavior reported in #47301, where the core Rendering the custom field with the same name alongside the core property would require introducing a separate attribute or structure to avoid name collisions. Since the issue specifically concerns the loss of the core If there is a preferred approach for exposing both the core property and the custom field in the API response, I would be happy to update the implementation accordingly. |
|
There is another, newer PR for the same issue: #47306 . |
|
This cannot be the correct solution as the next question would be why isnt the content of my custom field being included in the api response. All you are doing here is silently removing a valid field to solve one part of the problem. |
|
Thank you for the feedback @brianteeman I have pushed an update to the PR. The implementation now prefixes custom fields with custom_field_ when their name conflicts with an existing article property. This prevents the core property (such as images) from being overridden while still ensuring that the custom field value is included in the API response. |
|
I have tested this item 🔴 unsuccessfully on 67f8b3e This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/47304. |
|
@alikon I checked the test and noticed it was using the |
|
consider also that custom fields are used not only by com_content |

Pull Request resolves #47301
Summary of Changes
Custom fields are dynamically attached to the article object in the Content API view using
$item->{$field->name}.If a custom field has the same name as an existing article property (for instance,
imagesin this case), the custom field value overwrites the core article property. This results in incorrect API responses where core article data is replaced by custom field values.This patch prevents overriding existing properties by checking whether the property already exists before assigning the custom field value.
Testing Instructions
images.where
1is the article ID andxxxxxxxis the API token of a super-admin user.Actual result BEFORE applying this Pull Request
If a custom field named
imagesexists, the coreimagesattribute in the API response is overwritten and returned as an empty array.Expected result AFTER applying this Pull Request
The core article
imagesattribute is returned correctly and is not overridden by a custom field with the same name.Link to documentations
Please select:
Documentation link for guide.joomla.org:
No documentation changes for guide.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed