? Pending

User tests: Successful: Unsuccessful:

avatar SharkyKZ
SharkyKZ
15 Jul 2019

Pull Request for Issue #25574 .

Summary of Changes

Removes unneeded exception.

Testing Instructions

Create a contact.
VIew contacts list.

Expected result

Works.

Actual result

An error has occurred.
$i is not allowed to be 0

Documentation Changes Required

No.

avatar SharkyKZ SharkyKZ - open - 15 Jul 2019
avatar SharkyKZ SharkyKZ - change - 15 Jul 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 15 Jul 2019
Category Administration com_contact com_content
avatar brianteeman brianteeman - test_item - 15 Jul 2019 - Tested successfully
avatar brianteeman
brianteeman - comment - 15 Jul 2019

I have tested this item successfully on 91a699e

Marking as a success because it fixes the problem but I have no idea what the code was supposed to have done or why it was added


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

avatar brianteeman
brianteeman - comment - 15 Jul 2019

I have tested this item successfully on 91a699e

Marking as a success because it fixes the problem but I have no idea what the code was supposed to have done or why it was added


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

avatar richard67
richard67 - comment - 15 Jul 2019

Marking as a success because it fixes the problem but I have no idea what the code was supposed to have done or why it was added

Was added due to suggestion by @wilsonge : #25451 (comment).

avatar richard67
richard67 - comment - 15 Jul 2019

@SharkyKZ Title and testing instructions of this PR say it fixes only the contacts view, but in addition to that it fixes the articles view (administrator/components/com_content/Service/HTML/AdministratorService.php), or am I wrong?

avatar wilsonge
wilsonge - comment - 15 Jul 2019

If it's required it's required in both files.

But I don't get this. Before the PR this was a required variable - this was the signature.

public function featured($value = 0, $i, $canChange = true)

As far as I can see this is always used with a value. So how is this ever taking the default value of the function of 0. Or are we saying in some case here https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_contact/tmpl/contacts/default.php#L127 $i is somehow 0?

I'm not disputing we somehow broke this btw. But to understand the correct fix I need to understand why it's broken. Reverting that part isn't good enough - because if 0 is a valid value then it's a really bad default (I really wish we didn't have to set a default but.....)

avatar SharkyKZ
SharkyKZ - comment - 16 Jul 2019

Or are we saying in some case here https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_contact/tmpl/contacts/default.php#L127 $i is somehow 0?

Yes, $i is the array key:

foreach ($this->items as $i => $item) :

avatar richard67
richard67 - comment - 16 Jul 2019

@wilsonge If $i is an array key, would it make sense then to use -1 as default value and raise the exception if lower than zero?

avatar richard67
richard67 - comment - 16 Jul 2019

Or maybe just make the parameter mandatory? No need for exceptions then.

avatar astridx
astridx - comment - 20 Jul 2019

I have just come across this problem.

Does anyone know why $i was given a default value?

In the case of $published, the parameter $i is a mandatory parameter.

public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null,

In my opinion, we should keep this consistent in the project.

avatar SharkyKZ
SharkyKZ - comment - 20 Jul 2019

It's because of codestyle:

Arguments with default values must be at the end of the argument list

In the case of Joomla\Component\Contact\Administrator\Service\HTML::featured($value = 0, $i, $canChange = true) mandatory parameter $i was after optional parameter $value.

Maybe we could make $value required instead.

avatar astridx
astridx - comment - 20 Jul 2019

@SharkyKZ Thanks for explaining.

I would suggest that the value parameter becomes a mandatory field. In my opinion, it is a mistake if value is not set. This error would then have to throw an error and be properly processed further.

avatar richard67
richard67 - comment - 20 Jul 2019

Required $value parameter would also be more consistent to astridx's code snippet. Reading the code of these 2 functions modified by this PR, I think the $value parameter should be required, then you also can make the $i required. The exceptions you could add back and change them so $i lower than zero are not allowed, if that is useful.

avatar richard67
richard67 - comment - 20 Jul 2019

When testing this we should test both contacts view and com_content stuff, e.g. articles view, because this PR modifies files for both.

avatar wilsonge
wilsonge - comment - 22 Jul 2019

OK let's make $value required. I think in this case it's acceptable

avatar SharkyKZ SharkyKZ - change - 22 Jul 2019
Labels Added: ?
avatar wilsonge wilsonge - change - 23 Jul 2019
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-07-23 18:18:34
Closed_By wilsonge
avatar wilsonge wilsonge - close - 23 Jul 2019
avatar wilsonge wilsonge - merge - 23 Jul 2019
avatar wilsonge
wilsonge - comment - 23 Jul 2019

Thanks!

Add a Comment

Login with GitHub to post a comment