CSS class for page actions?

CSS class for page actions?

by Dave Balch -
Number of replies: 2
Hi,

I'd like to be able to specify CSS for the assign grading table page (but not other assign pages), but the page body CSS only exposes the page path (with "page-mod-assign-view").

The obvious feature that distinguishes the grading table page is "action=grading" on the URL, as that dictates what actions the page performs.

It seemed reasonable that other modules & pages might benefit from CSS indicating which action the page was executing, so I wrote a patch to add it to any page with an action param: MDL-52875.

Marina has suggested that it shouldn't be a global solution, but instead only modify mod assign, with "The action should really be appended to the path-mod-xxx class as it must be specific to the current path only".

AFAICT, this would be done by:

diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php
index 42fbba3..ae95a39 100644
--- a/mod/assign/locallib.php
+++ b/mod/assign/locallib.php
@@ -3470,7 +3470,9 @@ class assign {
* @return string
*/
protected function view_grading_page() {
- global $CFG;
+ global $PAGE, $CFG;
+
+ $PAGE->set_pagetype('mod-assign-grading');

$o = '';
// Need submit permission to submit an assignment.

...but I'm fairly sure that there will need to be some other changes as well.

So - which approach should I pursue, and if it's changing mod/assign, what else do I need to amend?

Average of ratings: -
In reply to Dave Balch

Re: CSS class for page actions?

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Personal opinion - I think this should use your global solution, so that an action class is added to body whenever such an action is present and not restricted to the assign module. In fact, are there other parameters that may occasionally be useful that could be added globally and are not already added to body classes (where they are used) ?

Not sure it needs a default - there just wouldn't be a class to pick up on for the css - but it would be fairly straightforward (I would have thought) to adapt your code something like

$actionclass = 'noaction';
if ($action = optional_param('action', '', PARAM_TEXT)) {
$actionclass = 'action-'.$action;
}
$this->add_body_class($actionclass);

Come to that - if it isn't added to core, I may start adding it to my themes anyway, ready for any future developments I may be doing smile

In reply to Richard Oelmann

Re: CSS class for page actions?

by Dave Balch -

Thanks for your thoughts - it's certainly how I was looking at it!