Problem

  1. drupal.org can only show 300 comments per page, because... that is the hard-coded upper limit.

Proposed solution (D8)

  1. Replace the select element with a #type number element, min=10, max=1000, step=10:


Proposed solution (D7)

  1. Allow a custom/higher value to be configured through other means (contrib module, Drush, variable editor, etc).

  2. Adjust Comment module's configuration form to offer the default #options to additionally include a pre-configured custom value, if any (just so that the form can be submitted without getting a form validation error).

    A pre-configured custom value must be an integer and meet the same properties of the #type number element as in D8. That is:

    $is_valid_custom_option = is_int($value) && $value >= 10 && $value <= 1000 && ($value % 10 === 0);
    

Comments

larowlan’s picture

Plus one to number in d8.
D7 drush vset works

sun’s picture

Issue summary: View changes

Added a concrete translation of the D8 number constraints into D7 PHP code to the summary.

wiifm’s picture

Status: Needs review » Reviewed & tested by the community

Patch seems sane to me, and due to the fact this is an HTML5 widget there is no need to further information (the D7 patch will probably need a better description to inform the user what is allowed and what is not).

Applied the patch to a fresh D8 HEAD, and it worked as intended.

webchick’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

#type => number indeed makes a lot more sense here.

Committed and pushed to 8.x. Thanks!

Sounds like this needs solving in 7 as well? Would have to use a different approach, though.

  • Commit 2516dc3 on 8.x by webchick:
    Issue #2239369 by sun: "Comments per page" setting cannot be configured...
mgifford’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.22 KB

I haven't checked that fapi allows all of this, but it's an initial port anyways.

steven jones’s picture

So an alternative patch, that does as is suggested in the issue summary for D7, i.e. it just adds an option to the select box on the form for the currently set variable. This means that this setting doesn't get lost when submitting the form, but doesn't introduce any UI changes.

Note that other modules do actually use the _comment_per_page function, like ctools.

dcam’s picture

The issue summary also suggests the value will need some validation, the same that the D8 number form element has. Should we at least verify that the value is an integer before displaying it as part of the options?

steven jones’s picture

StatusFileSize
new1.53 KB

@dcam Ah yes.

Find attached a patch that adds validation. Sadly we can only enforce is_numeric since is_int would return FALSE for any value set through Drupal's web UI (since they are strings that are just coerced into integers at the appropriate points. But the rest of the line should enforce that it's actually an integer (maybe stored as a string).

steven jones’s picture

Not sure if this needs tests or not, because the D8 version got in fine without tests.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

This works fine on my testing here http://s2acf8d9f2e2009f.s3.simplytest.me/node#overlay=admin/structure/ty...

I think it's fine for me to mark this RTBC, but I gave the first hack at backporting this before @Steven Jones went through it with @dcam.

dcam’s picture

Assigned: sun » Unassigned

RTBC +1 as far as the functionality goes. When I applied #9 I was able to set a custom value for the comments per page using Drush as long as it was a multiple of 10 and between 10 and 1000.

I am a little concerned, however, that this is basically going to be a hidden feature. Is there a policy about this sort of thing? Does this concern even matter at this point in the 7.x lifecycle?

steven jones’s picture

I am a little concerned, however, that this is basically going to be a hidden feature. Is there a policy about this sort of thing? Does this concern even matter at this point in the 7.x lifecycle?

Hmm...I would argue that all we're doing here is allowing people to know how to change that variable outside of the web UI to then not have it wiped out by the web UI. You can use Drush today to set the variable, and away you go. We're not introducing a new feature really.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: drupal-2239369-comments-per-page-form.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs review

Hm, this is a really unusual pattern... Also, isn't it a potential issue for any 'select' element where someone sets the variable to a value that the user interface doesn't allow?

Given that it's easy to fix using hook_form_alter() (without much more effort than using Drush to set a variable in the first place, you can pretty easily add an allowed value to the #options list using hook_form_alter()) I'm not sure we should commit this.

But maybe a separate issue looking at how to handle this scenario in the form API more generally would be a good idea?

  • webchick committed 2516dc3 on 8.3.x
    Issue #2239369 by sun: "Comments per page" setting cannot be configured...

  • webchick committed 2516dc3 on 8.3.x
    Issue #2239369 by sun: "Comments per page" setting cannot be configured...

  • webchick committed 2516dc3 on 8.4.x
    Issue #2239369 by sun: "Comments per page" setting cannot be configured...

  • webchick committed 2516dc3 on 8.4.x
    Issue #2239369 by sun: "Comments per page" setting cannot be configured...

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.