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 placeholder showing "Select a User" when in readonly mode (e.g. modified_by) #12627

Merged
merged 8 commits into from
Dec 8, 2016
Merged

Conversation

matrikular
Copy link
Contributor

@matrikular matrikular commented Oct 29, 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?

…odified_by)

Additional changes:
- Remove obsolete extracted variables that are not present for this field type
- Correct variable name in doc block to match extracted name
- Refactor code to remove ternary overuse
Additional changes:
- Satisfy Code Sniffer (e.g. @SInCE)
- Remove else block after variable initialisation
…pe($VARNAME)

Additional changes:
- Change JHtml::script() call to JHtml::_('script' ...) to allow overrides via custom register method
…modified_by)

Additional changes:
- 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
- Remove obsolete extracted variables that are not present for this field type
- Removed the class suffix from the hidden field
- Remove (Fix) obsolete whitespace in class attribute for the visible field when no suffix was entered
@brianteeman
Copy link
Contributor

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

Why not?

@matrikular
Copy link
Contributor Author

matrikular commented Oct 29, 2016

What do you mean with "Why not"?

@chmst
Copy link
Contributor

chmst commented Oct 30, 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.

@brianteeman
Copy link
Contributor

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.

@brianteeman
Copy link
Contributor

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

*
* @var string $userName The user name
* @var mixed $groups The filtering groups (null means no filtering)
* @var mixed $exclude The users to exclude from the list of users
* @var mixed $excluded The users to exclude from the list of users
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see the need to change this - it seems correct english to me

*
* @var string $userName The user name
* @var mixed $groups The filtering groups (null means no filtering)
* @var mixed $exclude The users to exclude from the list of users
* @var mixed $excluded The users to exclude from the list of users
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment - the english is correct to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not about correcting the word to be in the correct tense but to name the variable correctly. After "extracting" the information from $displayData, a variable $excluded is created. The doc block helps IDEs to autocomplete methods and variable names. As you can see in the original file here:
https://github.com/joomla/joomla-cms/blob/staging/layouts/joomla/form/field/user.php#L52
or the modified file here:
https://github.com/matrikular/joomla-cms/blob/49dea5de2a642a10b8735ad4185477192d87c7b8/layouts/joomla/form/field/user.php#L65
the doc block shows the wrong variable name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks for that explanation - it makes sense

Thats the problem when you create a long PR without explaining what you have changed and why you have changed things

@brianteeman
Copy link
Contributor

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

@bembelimen
Copy link
Contributor

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.

@brianteeman
Copy link
Contributor

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

@matrikular
Copy link
Contributor Author

matrikular commented Oct 30, 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, ...

@brianteeman
Copy link
Contributor

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

@brianteeman
Copy link
Contributor

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

@matrikular
Copy link
Contributor Author

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.

@brianteeman
Copy link
Contributor

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

@matrikular
Copy link
Contributor Author

Yes, I said that already.

@@ -14,7 +14,7 @@
*
* @since 1.6
*/
class JFormFieldUser extends JFormField implements JFormDomfieldinterface
class JFormFieldUser extends JFormField
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add the interface back here please

Missed that in the manual merge process. While I was working on the PR, the custom fields code got merged. Thanks @wilsonge.
@brianteeman
Copy link
Contributor

So you cannot remove it

@matrikular
Copy link
Contributor Author

matrikular commented Oct 30, 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.

@astridx
Copy link
Contributor

astridx commented Oct 31, 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.

@zero-24
Copy link
Contributor

zero-24 commented Dec 5, 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.

@zero-24
Copy link
Contributor

zero-24 commented Dec 5, 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.

@zero-24 zero-24 added this to the Joomla 3.7.0 milestone Dec 5, 2016
@zero-24
Copy link
Contributor

zero-24 commented Dec 5, 2016

RTC for 3.7.0 thanks.


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Dec 5, 2016
@brianteeman
Copy link
Contributor

Sorry but I still disagree with this PR

@zero-24
Copy link
Contributor

zero-24 commented Dec 5, 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 😄

@chmst
Copy link
Contributor

chmst commented Dec 5, 2016

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

@infograf768
Copy link
Member

Looks like working fine here.

@wilsonge
Copy link
Contributor

wilsonge commented Dec 5, 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.

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 5, 2016
<input type="hidden" id="<?php echo $id; ?>_id" name="<?php echo $name; ?>" value="<?php echo (int) $value; ?>"
class="field-user-input <?php echo $class ? (string) $class : ''?>"
data-onchange="<?php echo $this->escape($onchange); ?>"/>
<input type="hidden" id="<?php echo $id; ?>_id" name="<?php echo $name; ?>" value="<?php echo (int) $value; ?>" class="field-user-input" data-onchange="<?php echo $this->escape($onchange); ?>" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use $inputAttributes ['class']

@wilsonge
Copy link
Contributor

wilsonge commented Dec 8, 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

@wilsonge wilsonge merged commit 0838299 into joomla:staging Dec 8, 2016
@wilsonge
Copy link
Contributor

wilsonge commented Dec 8, 2016

Thanks @matrikular :)

@matrikular matrikular deleted the patch-15 branch March 27, 2017 14:51
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.

None yet

9 participants