Skip to content
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

Merged
merged 1 commit into from
Nov 21, 2015
Merged

Conversation

izharaazmi
Copy link
Contributor

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.

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.
@izharaazmi
Copy link
Contributor Author

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)

@zero-24
Copy link
Contributor

zero-24 commented Nov 11, 2015

Can This ne tested somehow? E.g. With a extension that don't work bevor but after that patch?

@izharaazmi
Copy link
Contributor Author

@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.
That issue is fixed here along with the fix made by #3737. Therefore both the test cases should pass now.

The comment #3737 (comment) by @vietvh mentions some issue regarding previous change.

@vietvh
Copy link
Contributor

vietvh commented Nov 12, 2015

@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:

  1. form > fieldset > field
  2. form > fields > fieldset > field

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?

@izharaazmi
Copy link
Contributor Author

@vietvh You are right about the patterns used commonly. But that is not restricted by Joomla, and the nesting like fields > fields > fields > ... at any level creates the form elements at the same depth.

I'd also like to mention that fieldset does not affect the nesting of input fields in the output.

Therefore to replicate the nesting issue in minimal code I just used such nesting. Hope this answers your query.

@izharaazmi
Copy link
Contributor Author

@vietvh If you tested the PR with your code and the given test case. Please update the test result here.

@vietvh
Copy link
Contributor

vietvh commented Nov 17, 2015

Worked fine for me, this patch fixes the following:

  1. It does not generate PHP warning (as mentioned in [#33834] Fixed JForm::bind for nested JObject argument #3737)
  2. It does not break the current JForm behavior (like [#33834] Fixed JForm::bind for nested JObject argument #3737 did)
  3. It allows nested form fields as in test case above.

@izharaazmi
Copy link
Contributor Author

@Kubik-Rubik The PR for the extended issue reported after merge in #3737 is here. Kindly have a look at your convenience.

@roland-d
Copy link
Contributor

I have tested this item ✅ successfully on 64bc802

I have tested this successfully. The tags were not working before, they are working now.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8379.

@roland-d roland-d added this to the Joomla! 3.5.0 milestone Nov 21, 2015
@joomla-cms-bot joomla-cms-bot removed this from the Joomla! 3.5.0 milestone Nov 21, 2015
@roland-d
Copy link
Contributor

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.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Nov 21, 2015
@roland-d roland-d added this to the Joomla! 3.5.0 milestone Nov 21, 2015
rdeutz added a commit that referenced this pull request Nov 21, 2015
Fix Jform::bind method JObject handling
@rdeutz rdeutz merged commit dc13ef5 into joomla:staging Nov 21, 2015
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Nov 21, 2015
@izharaazmi izharaazmi deleted the jform-bind branch August 23, 2016 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants