-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Jform::bind method JObject handling #8379
Conversation
Currently it converts all nested objects to array silently (see joomla#3737). Some components relying on old behavior (prior to joomla#3737) may expect object values for the form fields. This fix does not process the entire nested structure, instead converts only binding levels to array for internal iterations.
Use the following code to test: $xml = '<form>
<fields name="level1">
<fields name="level2">
<field name="field1" type="text"/>
<field name="field2" type="custom"/>
<field name="field3" type="custom"/>
</fields>
</fields>
</form>';
$array = array(
'level1' => array(
'level2' => array(
'field1' => 'field_value',
'field2' => array(
'a' ,
(object) array('b' => 'B' ,'c' => 'C')
),
'field3' => (object) array('a' => 'AA' ,'b' => 'BB')
)
)
);
$data = Joomla\Utilities\ArrayHelper::toObject($array, 'JObject');
$form = JForm::getInstance('JFormBindTest', $xml);
$form->bind($data);
echo '<pre>';
print_r($data);
print_r($form);
echo '</pre>'; @vietvh Please check this out and cross test against #3737 (comment) |
Can This ne tested somehow? E.g. With a extension that don't work bevor but after that patch? |
@zero-24 I am not particularly seeing any such extension, however the referenced PR (#3737) has changed the behavior of JForm bind method in this regard, as a result of which few extensions are likely to break. The comment #3737 (comment) by @vietvh mentions some issue regarding previous change. |
@izharaazmi : the new change in this pull request worked fine with my code. At least from what I tested. The common form that I've seen from core Joomla components and many 3rd extensions is using this structure:
From your use case, you are nesting 2 same tags (form > fields > fields > field). This is the first time I see this therefore I am a little bit curious, why did you have to use that instead of the common pattern 1 and 2 above? |
@vietvh You are right about the patterns used commonly. But that is not restricted by Joomla, and the nesting like I'd also like to mention that Therefore to replicate the nesting issue in minimal code I just used such nesting. Hope this answers your query. |
@vietvh If you tested the PR with your code and the given test case. Please update the test result here. |
Worked fine for me, this patch fixes the following:
|
@Kubik-Rubik The PR for the extended issue reported after merge in #3737 is here. Kindly have a look at your convenience. |
I have tested this item ✅ successfully on 64bc802 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8379. |
Setting to RTC as we have 2 successful tests. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8379. |
Fix Jform::bind method JObject handling
Currently it converts all nested objects to array silently (see #3737). Some components relying on old behavior (prior to #3737) may expect object type values for the form fields.
This fix does not process the entire nested structure, instead converts only binding levels to array for internal iterations.