? ? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
10 Mar 2018

Pull Request for Issues like #19735 and #17801 and for PRs #18188, #17837, #18207, #19742, #19753, #19850.

Summary of Changes

As #19753 revealed that the request data should be normalised only for com_fields and we do not want to have extension specific code in the libraries. This pr adds a new event which sends the data for normalisation in the controller. Like that the fields plugin can then modify the data.

Remark:
I was unsure about the plugin name, any feedback is welcome.

Testing Instructions

  • Create custom user fields.
  • Edit a user and fill any data in custom fields.
  • Add the following code to the file /administrator/components/com_content/content.php after line 16:
    JFactory::getUser($USER_ID)->save();.
    Replace the value $USER_ID with the user you have edited.

Expected result

The user custom field data is still saved on the user.

Actual result

The user custom fields data on the user are deleted.

avatar laoneo laoneo - open - 10 Mar 2018
avatar laoneo laoneo - change - 10 Mar 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 10 Mar 2018
Category Administration com_fields Libraries Front End Plugins
e8f8fdf 10 Mar 2018 avatar laoneo CS
avatar laoneo laoneo - change - 10 Mar 2018
Labels Added: ?
avatar ggppdk
ggppdk - comment - 10 Mar 2018

value '0' is quite common,
the checks empty($value) and empty($value[0]) should be changed

avatar laoneo
laoneo - comment - 10 Mar 2018

I'm also not sure if strlen is the solution as asked here #19753 (comment).

avatar ggppdk
ggppdk - comment - 10 Mar 2018

I'm also not sure if strlen is the solution as asked here

well, $value can not be an object, it is either
null, boolean, string, or array

null, boolean, string are all of them 'valid' inputs for strlen

so the only check that needs to be made is that $value and $value[0] are not an array

consider "empty" if
is_array($value) ? !count($value) : !strlen($value)
the above should replace empty($value)

is_array($value[0]) ? !count($value[0]) : !strlen($value[0])
the above should replace empty($value[0])

avatar joomla-cms-bot joomla-cms-bot - change - 12 Mar 2018
Category Administration com_fields Libraries Front End Plugins Administration com_fields Front End com_users Libraries Plugins
avatar Ruud68
Ruud68 - comment - 12 Mar 2018

I have tested this item successfully on 5db8f95

Tested on both com_content and com_user (back-end and front-end)

  1. saving with empty checkbox removes checkbox previous value from table = OK
  2. removing value from field removes value from table = OK
  3. setting field to only display on administrator and the save article or user on front-end retains value for the field in the table = OK
  4. changing user groupmembership via API retains field values for this user = OK

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19884.
avatar Ruud68 Ruud68 - test_item - 12 Mar 2018 - Tested successfully
avatar Ruud68
Ruud68 - comment - 13 Mar 2018

pinging @Denitz , @joomdonation , @ggppdk on this PR.

I have been trying to test for all your (related) issues and I think that they are fixed with this PR.
Can you test as well so we can get 'the show on the road' :)

Also calling on @tassosm and @regularlabs as I know they develop custom fields and (could) have an interest in also getting this fixed :)


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

avatar Quy
Quy - comment - 17 Mar 2018

@laoneo As @ggppdk has commented, the value of 0 will be cleared and not saved which I have confirmed.

avatar laoneo
laoneo - comment - 17 Mar 2018

Added the proposal from @ggppdk. Can you guys please test again?

avatar Ruud68
Ruud68 - comment - 17 Mar 2018

Hi @laoneo , it fails :(
I have a text field and a checkbox field. It only saves one of them: when changing the checkbox, then the text field is deleted and vv. reverting $needsDelete in 9c68d5b fixes it ($needsDelete = empty($value[0]);)

EDIT: fixed this via new PR against your repo

avatar Ruud68
Ruud68 - comment - 17 Mar 2018

Hi @laoneo just did two PR's against your repo.
with these PR's it is possible to save value 0 as actual value AND it corrects the incorrect behaviour on single character text values (strlen = 1)


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

avatar Quy
Quy - comment - 17 Mar 2018

Now clicking the Save button two times will clear entered values.

avatar Ruud68
Ruud68 - comment - 17 Mar 2018

@Quy could you try this: Digital-Peak#12
That should fix it.

avatar Quy
Quy - comment - 17 Mar 2018

@Ruud68 Fixed. Thank you!

avatar ggppdk
ggppdk - comment - 17 Mar 2018

Ok please let me explain things
the empty() check was in 2 places
now both are patched

but

@Ruud68

It was:

$needsUpdate = !empty($value[0]);

It was patched to be

$needsUpdate = is_array($value[0]) ? !count($value[0]) : !strlen($value[0]);

The negation was of !empty($value[0])

  • was lost

Now clicking the Save button two times will clear entered values.

that is why it is not working !

the complex expression that you suggest in your PR fixes it but it is not needed be like that,
you are just readding the negation back with a more complex expression

so just re-add the negation:

$needsUpdate = ! (is_array($value[0]) ? !count($value[0]) : !strlen($value[0]));
//or better
$needsUpdate = is_array($value[0]) ? count($value[0]) : strlen($value[0]));
avatar Ruud68
Ruud68 - comment - 17 Mar 2018

the complex expression that you suggest in your PR fixes it but it is not needed be like that,
you are just readding the negation back with a more complex expression

Agree and @laoneo already simplified that. the code I suggested was a quick-mockup from me trouble shooting where things went wrong :)

With this last PR Digital-Peak#12 it works :)
with your code:

$needsUpdate = is_array($value[0]) ? count($value[0]) : strlen($value[0]);

When this PR is committed I will be re-doing all my test cases (which are already a lot :))

avatar laoneo
laoneo - comment - 17 Mar 2018

Pr's from @Ruud68 got merged.

avatar Ruud68
Ruud68 - comment - 18 Mar 2018

I have tested this item successfully on 2756bb8

Tested on both com_content and com_user (back-end and front-end)

  1. saving with empty checkbox removes checkbox previous value from table = OK
  2. removing value from field removes value from table = OK
  3. setting field to only display on administrator and the save article or user on front-end retains value for the field in the table = OK
  4. changing user groupmembership via API retains field values for this user = OK
  5. saving value of 1 character saves okay
  6. saving value 0 saves okay
    This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19884.
avatar Ruud68 Ruud68 - test_item - 18 Mar 2018 - Tested successfully
avatar Ruud68
Ruud68 - comment - 18 Mar 2018

Pr's from @Ruud68 got merged.

all credits for my last PR's go to @ggppdk. Some say they where inspired, I just copied his code :)))

avatar Ruud68
Ruud68 - comment - 19 Mar 2018

@Quy and @ggppdk can you find some time to test and if okay approve?

avatar Quy
Quy - comment - 19 Mar 2018

I have tested this item successfully on 2756bb8


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

avatar Quy Quy - test_item - 19 Mar 2018 - Tested successfully
avatar Quy Quy - change - 19 Mar 2018
Status Pending Ready to Commit
avatar Quy
Quy - comment - 19 Mar 2018

RTC


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

avatar mbabker mbabker - change - 25 Mar 2018
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-03-25 14:55:12
Closed_By mbabker
Labels Added: ?
avatar mbabker mbabker - close - 25 Mar 2018
avatar mbabker mbabker - merge - 25 Mar 2018

Add a Comment

Login with GitHub to post a comment