-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add callbacks to add or keep section number #117
Add callbacks to add or keep section number #117
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making PR for the issue.
It looks ok but some variable/function name are confusing.
classes/form/section_select_form.php
Outdated
@@ -45,6 +45,8 @@ | |||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |||
*/ | |||
class section_select_form extends moodleform { | |||
/** Int array of allowed values */ | |||
protected $allowedvalues = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the variable name does not really mean the values.
maybe $targetsections or something is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @TomoTsuyuki
Thanks for your review, I have changed it to $allowedsections, only contains section numbers which are allowed to be chosen.
classes/form/section_select_form.php
Outdated
* @param array $attributes the attributes | ||
* @return void | ||
*/ | ||
private function is_allowed(bool $allowcondition, int $optionnumber, array &$attributes): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function name sounds like for checking value and return bool if condition is ok.
maybe set_radioption
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed this to set_radio_option
classes/massactionutils.php
Outdated
* @param string $callbackname the name of the callback function | ||
* @return mixed|null none determined return type | ||
*/ | ||
private static function run_course_format_callback(int $courseid, string $format, string$callbackname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a space between string
and $callbackname
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a space
$this->is_allowed($canaddnewsection, $targetsectionnum + 1, $attributes); | ||
$radioarray[] = $mform->createElement('radio', 'targetsectionnum', '', | ||
get_string('newsection', 'block_massaction'), $targetsectionnum + 1, $attributes); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOUND 1 ERROR AFFECTING 1 LINE
140 | ERROR | [x] Functions must not contain multiple empty lines in a row; found 2 empty lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the redundant empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TomoTsuyuki for your review
I have updated the patch
33c3af5
to
3506e74
Compare
Hi @Syxton , Hope you are doing fine. Would you please help with the review once you have time and let me know if there is any issue I need to address? Regards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tuanngocnguyen I have looked over these changes and they seem like they are good. @PhMemmel Do you have any concerns with moving this forward?
@Syxton Won't be able to have a look for at least 2 weeks, sorry. If you want to wait, I will have a look and provide feedback. |
Just one thought when speaking of callbacks... Without having a closer look at the code ... would it be maybe better to use the new hook api for that implementation? So all kinds of Plugin could hook into this and we do not need to look for callbacks in course formats? |
Thanks for your comment. I am happy to wait for your review. I think the limitation feature should be applied to course format. If other plugins can implement the hooks/callbacks, we may go into a case where a course has multiple blocks with the feature. One allows to add new section, one disallows to add new section. I may lead to unpredictable behavior. Please let me know your opinion. Regards |
Hi everyone, I now took some time to come back at this and thought a little bit more about this approach:
Because of this I have reworked the current callback from #99 and included an alternative for this PR using a hook, see #118. To show, how this hook can be used I also pushed a moodle branch demonstrating the hook usage for format_topics: moodle/moodle@main...PhMemmel:moodle:Hook_example_block_massaction @Syxton and also @tuanngocnguyen and @TomoTsuyuki: Let me know what you are thinking of this. From my point of view this would be the better approach for on the one hand addressing your (very specific) use cases and on the other hand keep the interactions with other plugins well structured and controlled. Regarding your concerns @tuanngocnguyen about the course format having to be the only plugin controlling the section restrictrions: I designed the hook in a way so that every plugin which hooks in can disable additional sections and options, but never can add them again. So your course format callback should be good. @Syxton As my PR is more or less an API change we would have to think about how to deal with branches and releases. Also, this PR currently uses dependency injection features which is requiring moodle 4.4. If we need to be downwards compatible to moodle 4.3 this is easily reworkable however, makes it hard to unit test though. |
b7ea080
to
d3a086a
Compare
@Syxton Glad to hear and thank you very much for the feedback. Will wait for some additional feedback from @tuanngocnguyen @TomoTsuyuki, especially if my implementation addresses all of their use cases. After that I'll finalize my PR, will finally put it against master branch which then will be our new branch for Moodle 4.4 onwards. |
Thanks for your work on the issue.
As Moodle 4.1 is LTS, would it still be possible for our PR to be integrated into a separated branch for the moodle version ? Please let me know if you require additional work for the MOODLE_401_STABLE branch? Regards |
3506e74
to
975d7cf
Compare
I have rebased the PR to MOODLE_401_STABLE |
Thank you @tuanngocnguyen for the feedback. I feared you would answer this :) Trying to be as objective as possible while considering all concerns I personally come to the conclusion that it would be best overall to not integrate this PR but instead use the resources on the review of the hook rework/approach. @tuanngocnguyen As we will not develop the current code any further it probably should be no big effort for you to integrate your PR in a temporary fork. As soon as you update, you will be able to switch to the new master branch and implement the new hook. @Syxton @TomoTsuyuki @tuanngocnguyen Is this fine for everyone? |
@PhMemmel I agree. I think that it is late in the game to be adding features to the 401 branch. Moodle LTS general support ended in December of '23 with only security support till 2025. I can only speak for myself that my attention is spread very thin, so I think it best to instead of adding a feature for 4.1, we focus on the long term solution with hooks and @TomoTsuyuki & @tuanngocnguyen can keep their fork with this PR until they are able to upgrade their Moodle to the hooks capable version. |
Thanks all for your work. I am closing this WR. |
Hi @Syxton ,
I have created a PR for this issue:
#115
I have added 2 callbacks for course format to determine if a user can select "Add new section"/"Keep original section"
Would you please have a look and let me know your opinion?
Thanks