joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.77k stars 3.65k forks source link

onContentPrepareForm event $data is unpopulated #14851

Closed bassmanpaul closed 2 years ago

bassmanpaul commented 7 years ago

Hi, I'm not sure if this is expected behaviour or not but when saving a module, the $data object in onContentPrepareForm( $form, $data ); is a blank array.

My content plugin needs to add additional fields to the $form based on the type of module which can be found in $data->module (e.g. 'mod_menu'). To do this, the onContentPrepareForm() fires on load and on save where I must bind my fields in both cases.

Unfortunately, the $data is unpopulated on save. Is this intended?

I've found another instance of this cropping up a few years back: https://developer.joomla.org/joomlacode-archive/issue-29145.html but a workaround was suggested rather than the issue being directly addressed/fixed.

Thoughts welcome!

PhilETaylor commented 6 years ago

I can replicate this and have seen this many times over the years....

Before this line $data is populated correctly

https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_modules/models/module.php#L553

after it $data is gone.

This is because some reference something is happening here https://github.com/joomla/joomla-cms/blob/6de2b00858e91bd64e7c410a6ed617d455f62d64/libraries/src/MVC/Model/FormModel.php#L237

passing in the $data to loadForm and using it instead of creating a new blank array at https://github.com/joomla/joomla-cms/blob/6de2b00858e91bd64e7c410a6ed617d455f62d64/libraries/src/MVC/Model/FormModel.php#L237 seems to work

but this is not the real fix I dont think. It works but it tacky.

Quy commented 6 years ago

Related issue #17700 about empty $data.

ReLater commented 4 years ago

I'd say that it would be a B\C break to change that behavior in J!3. For me it's sometimes a welcome behavior to identify if form loading/preparing is on/after saving or not. But I'm just a dilettante and can't judge if it's a bug.

grantg182 commented 3 years ago

Angels died today when I had to commit code to work around this issue in 3.9. Yet to test in J4.

brianteeman commented 2 years ago

Thank you for raising this issue.

Joomla 3 is now in security only mode with no further bug fixes or new features.

As this issue doesn't relate to Joomla 4 it will now been closed.

If we are mistaken and this does apply to Joomla 4 please open a new issue (and reference this one if you wish) with updated details for testing in Joomla 4. cc @zero-24