? Failure

User tests: Successful: Unsuccessful:

avatar matrikular
matrikular
29 Oct 2016

Summary of Changes

Fix placeholder showing "Select a User" when in readonly mode (e.g. modified_by)

Additional changes:
Layout (Mootools Version ~ hathor):

  • Change htmlspecialchars($VARNAME, ENT_COMPAT, 'UTF-8') to $this->escape($VARNAME)
  • Refactor code to remove the ternary overuse
  • Change JHtml::script call to JHtml::_('script' ...) to allow overrides via custom register method
  • Correct variable name ($exclude) in doc block to match extracted name ($excluded)
  • Remove obsolete extracted variables that are not present for this field type

Layout (jQuery / Bootstrap Version ~ isis):

  • Same as for the Mootools implementation + removed the class suffix from the hidden field
  • Remove (Fix) obsolete whitespace in class attribute for the visible field when no suffix was entered

JFormFieldUser:

  • Satisfy Code Sniffer (e.g. @since)
  • Remove else block after variable initialisation
  • Fixe typo in doc block of the added custom fields handling method
  • Changed getExcluded method return value to match doc block

Testing Instructions

  • Open a new banner'' item in the back-end and switch to the "Publishing" tab.
    Before the patch, the "Modified By" field shows a "Select a User" placeholder. Since you cannot really select a user here, that text is obsolete in that context.

''You could also open a new article but in the hathor template, the modified_by field won't show up until the article has actually been modified which would then of course override the placeholder. Hence, a banner item.

  • Apply the patch, refresh the view or open another banner item. The placeholder should be gone.

Now, this PR changes both the "old" Mootools and the jQuery / Bootstrap implementation of the layout(s), where Mootools version is currently the "default". I put default in quotes because we think of isis as the default admin template and that template has got an override for the field layout which uses jQuery / Bootstrap code to open the modal window.

So, to fully verifiy that everything works as expected, please make sure that you test the field both in hathor and isis. That is, not only confirm that the placeholder text disappears from the "Modified By" field, but also that the "Created By" still works as it should (because it is the same field).

Caveat

I would go so far and move a few more lines, but before that, I would like your opinion first.

  • Even though JHtml::script makes sure that a script only gets included ones, I would move the call for the modal stuff inside the !readonly block. The "Modified By" field is almost always(?!) added with the unset filter and readonly attribute, so no modal code is really needed here and neither is the hidden input field.

Long story short: Any objections?

avatar matrikular matrikular - open - 29 Oct 2016
avatar matrikular matrikular - change - 29 Oct 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 Oct 2016
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 29 Oct 2016
Category Administration Templates (admin) Layout Libraries
avatar brianteeman
brianteeman - comment - 29 Oct 2016

"Select a User" placeholder. Since you cannot really select a user here,
that text is obsolete in that context.

Why not?

avatar matrikular
matrikular - comment - 29 Oct 2016

What do you mean with "Why not"?

avatar chmst
chmst - comment - 30 Oct 2016

I agree with @matricular that the placeholder is wrong. "Select a user" cannot be performed if there is nothing to select.
When creating a new item, it would be nice if the modification fields are not shown at all.
Despite of this, I've tested the patch successfully (on 3.6.4) in the banner component - it works as described in isis and hathor and removes the placeholder.
In the Banner component the selection of an author does not work while creating a new item - neither before the patch nor after the patch, so this is another issue.
Concerning the Mootools and jQuery - someone with more experience is needed.

avatar brianteeman
brianteeman - comment - 30 Oct 2016

Sorry maybe I am being an idiot but I do not understand what you are talking about when you say you can not select a user - see the movie below screen shot 2016-10-30 at 05 32 20


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

avatar brianteeman
brianteeman - comment - 30 Oct 2016

Sorry I get it now you just meant the "modified by Field not any of the others

avatar brianteeman
brianteeman - comment - 30 Oct 2016

Finally I understand what you were referring to but I cant help but feeling that this is the wrong way to fix it. It feels like using a sledgehammer to crack a nut

avatar bembelimen bembelimen - test_item - 30 Oct 2016 - Tested successfully
avatar bembelimen
bembelimen - comment - 30 Oct 2016

I have tested this item successfully on 49dea5d

I think the "summary of changes" in this PR is wrong (or too modest).

Sure it "fixes" the wrong "Select a User" string, but a better description would be, that this patch fixes a lot of small code quality issues and make the code a lot more readable.

In this sense I fully agree with this PR (and I'm looking forward to see this improvements in the 100 other layouts, too)


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

avatar brianteeman
brianteeman - comment - 30 Oct 2016

Please see #12639 for an alternative approach which I think is much simpler - assuming I have addressed the correct issues

avatar matrikular
matrikular - comment - 30 Oct 2016

To be perfectly honest. This is nothing to have "feelings" for.

The ternary overuse is a bad habbit and, apart from being hard to read and / or maintain, raises the NPath and cyclomatic complexity of a the code. The philosophy behind that is to get rid of else blocks and initialise variables with a prefered default value.

Fixing a return value for a method that, being in the cascade of files responsible for displaying the field, to match the description in its doc block, is the thing to do when you notice it. The same goes for renaming (correcting) the variable name in the doc block and all the other corrections / improvements I made in this PR.

As an example: this would show up for someone working with a custom user layout, if I had not removed the obsolete variables.

errors_in_layout

Don't get me wrong, I will happily explain my intensions for the changes to anyone, after spending hours putting everything together though, to me, it seems rude to see a question like "Why not", just minutes after opening the PR.

And now opening another PR that dublicates code blocks all together, ...

avatar brianteeman
brianteeman - comment - 30 Oct 2016

The Why Not referred to the quoted text (which possibly didnt get dispayed in your email client) and as you see later it referred to a misunderstanding as I thought you were talking about a different field

avatar brianteeman
brianteeman - comment - 30 Oct 2016

Can you explain why you made this change

Change htmlspecialchars($VARNAME, ENT_COMPAT, 'UTF-8') to $this->escape($VARNAME)

If I remember correctly there were very specific reasons for this

avatar matrikular
matrikular - comment - 30 Oct 2016

Yes, it was to make sure that UTF8 is used for htmlspecialchars in PHP versions below 5.4.

As well as the JViewLegacy class, JLayoutBase has a method called escape which does exactly that:
https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/layout/base.php#L114

It was used in the user field layout here:
https://github.com/joomla/joomla-cms/blob/staging/layouts/joomla/form/field/user.php#L82

So instead of having to change every occurrence of htmlspecialchars($VARNAME, ENT_COMPAT, 'UTF-8') you could use the escape method and only have to change one place (JLayoutBase) if the implementation should change for whatever reason.

Trivia:
There are debates in the interwebs if whether or not one should create proxy methods for core PHP functions but, for the unforeseeable future, that method is available in JLayoutBase, JViewLegacy and some more to be used for exactly that purpose.

avatar brianteeman
brianteeman - comment - 30 Oct 2016

Yes, it was to make sure that UTF8 is used for htmlspecialchars in PHP versions below 5.4.

The supported minimum version of Joomla is 5.3.10

avatar matrikular
matrikular - comment - 30 Oct 2016

Yes, I said that already.

avatar brianteeman
brianteeman - comment - 30 Oct 2016

So you cannot remove it

avatar matrikular
matrikular - comment - 30 Oct 2016

Remove what? Did you not understand any of what I just explained? (no offense)

If you have any questions regarding programming principles like DRY, feel free to contact me in Glip and I will try my best to explain them, but please - let's not make this discussion here any more daunting.

avatar astridx
astridx - comment - 31 Oct 2016

The place holder is wrong. There is no doubt about it.

I agree with @chmst When creating a new item, it would be nice if the modification fields are not shown at all. But as we use this form for modification too, this is a good compromise. Perhaps it would be nice to fill it with a text like “will be filled automatic”. But the solution here is an improvement because it corrects something that is wrong at the moment.

I've tested the patch successfully in the Banner and the News Feeds component - it works as described. I tested it in isis and hathor. It removes the place holder but the text in “created by” remains.

Perhaps I understood something wrong, but for me in the Banner component the selection of an author works with and without the patch while creating a new item.

avatar zero-24
zero-24 - comment - 5 Dec 2016

I have tested this item successfully on 617a3d9


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

avatar zero-24 zero-24 - test_item - 5 Dec 2016 - Tested successfully
avatar zero-24
zero-24 - comment - 5 Dec 2016

It removes the place holder but the text in “created by” remains.

this is correct as this is a filed where you can change the value from the backend ;)


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

avatar zero-24 zero-24 - alter_testresult - 5 Dec 2016 - astridx: Tested successfully
avatar zero-24 zero-24 - change - 5 Dec 2016
The description was changed
Milestone Added:
Status Pending Ready to Commit
avatar zero-24 zero-24 - change - 5 Dec 2016
Milestone Added:
avatar zero-24
zero-24 - comment - 5 Dec 2016

RTC for 3.7.0 thanks.


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

avatar zero-24 zero-24 - change - 5 Dec 2016
Labels Removed: ?
avatar zero-24 zero-24 - edited - 5 Dec 2016
avatar brianteeman
brianteeman - comment - 5 Dec 2016

Sorry but I still disagree with this PR

avatar zero-24
zero-24 - comment - 5 Dec 2016

Why?

RE: this->escape vs htmlspecialchars see: https://github.com/joomla/joomla-cms/blob/3.6.4/libraries/joomla/view/html.php#L78

it uses the same code so no problem 😄

avatar chmst
chmst - comment - 5 Dec 2016

I've retested this item successfully. Why do you disagree?

avatar infograf768
infograf768 - comment - 5 Dec 2016

Looks like working fine here.

avatar wilsonge wilsonge - change - 5 Dec 2016
Status Ready to Commit Needs Review
Labels
avatar wilsonge
wilsonge - comment - 5 Dec 2016

I'm putting this into needs review so I (or another maintainer) can do a code review before it gets merged


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

avatar wilsonge
wilsonge - comment - 8 Dec 2016

This looks good to me :) I've commented one thing that needs changing (that's pretty small) but I'm happy for this to be merged when it's done

avatar wilsonge wilsonge - reference | 0838299 - 8 Dec 16
avatar wilsonge wilsonge - merge - 8 Dec 2016
avatar wilsonge wilsonge - close - 8 Dec 2016
avatar wilsonge wilsonge - change - 8 Dec 2016
Status Needs Review Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2016-12-08 23:44:08
Closed_By wilsonge
avatar wilsonge wilsonge - close - 8 Dec 2016
avatar wilsonge wilsonge - merge - 8 Dec 2016
avatar wilsonge
wilsonge - comment - 8 Dec 2016

Thanks @matrikular :)

avatar cpfeifer cpfeifer - reference | fb3e6ba - 22 Dec 16

Add a Comment

Login with GitHub to post a comment