Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am not sure of the reason why the RRule form is build completely in JS. I had a small alteration for a client to remove the "Never" option and to do this I had to alter the library and copy the date_recur_rrule.widget.js file and remove the 3 lines.
If this was a standard Drupal form then I could just unset the never option on the form array and it is all done.
Basically creating a new form element type would be the best way to create this form. This way if other module want the rrule element it is very easy to change.
Comment | File | Size | Author |
---|---|---|---|
#31 | interdiff-date_recur-2866563-27-30.txt | 37.63 KB | chOP |
#31 | date_recur-rrule_field_drupal_form-2866563-30.patch | 116.98 KB | chOP |
Comments
Comment #2
Frando CreditAttribution: Frando as a volunteer commentedThe reason for having the widget in JS is that the form is quite interactive, and that I could reuse existing code for a jQuery-based RRULE widget (see rrule.widget.js).
Of course you're right that a new Drupal form element would be best. I don't know if I have time soon to get to it, so feel free to work on this. I wouldn't actually create the individual form elements in Drupal (due to them being highly interconnected in JS, and the JS also includes custom logic to parse out the values by their names, which correspond to the matching properties in rrule.js). Instead, I'd create an element that has all relevant options, which are then passed to JS as settings, and then adapt rrule.widget.js to behave differently (or exclude/include form fields) based on these options.
Comment #3
gordon CreditAttribution: gordon as a volunteer commentedWorking on this change now, found that there is a relation to the issue https://www.drupal.org/node/2419131 so #states will work on datetime fields.
Comment #4
gordon CreditAttribution: gordon as a volunteer commentedComment #5
gordon CreditAttribution: gordon as a volunteer and at Heydon Consulting for Deloitte Digital commentedHere is a patch which replaces the current javascript form with a Drupal based form. Other than some difficulties from the templates and having to do some fun things it is all working.
There is also some workarounds to allow it to work with the datetime_tweaks module it is all working.
Also there is going to need some work on it as well, but I think all the heavy lifting has been done. Now it should just be some cleaning up and chasing some bugs.
Comment #6
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedHere is a small cleanup of the title of the widget not being repeated twice.
Comment #7
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedSome more changes so that you can set values in the rrule element during hook_form_alter() before the process() has been run.
Comment #8
realityloopThe UNTIL value doesn't get converted on storage so the conversion to the site timezone when loading the value was causing the value to increment/decrement on edit and save of content using this field depending on your site timezone settings. I've removed this conversion in this updated patch.
Comment #9
realityloopPatch missing added files and wouldn't apply, reroll.
Comment #10
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedBugger, I was originally setting the timezone because I was thought I was working with a text date time instead of a DateTime object.
Attached is the interdiff.txt
I also need to add back in the excluded/included datetimes.
Comment #11
realityloopReroll to fix typo in libraries link to moment.min.js (instead of moment-min.js)
Comment #12
realityloopAdded fix for js issue with monthly reoccuring droppdown that contains checkboxes.
Comment #13
realityloopFuther JS fix
Comment #14
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedJust checking #13 and I can't see any difference between #12 and #13
Comment #15
realityloop@gordon looks like Victor sent me the wrong file.. will update tomorrow
Comment #16
realityloopupdate, closes the monthly dropdown when you defocus it.
Comment #17
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedThis is a good fix, I just ported over the old and it was a PIA to work with.
However the file assets/date_recur_rrule.js has had it line endings changed to ^M
Comment #18
realityloophopefully this fixes that.
Comment #19
realityloopLets try that one more time.
Comment #20
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedI have done some more work on this. I cleaned up the js a bit to comply with the Drupal Javascript coding standards.
Also added back in the dependency on the start date so that you are required to enter a start date to enter the RRule. I did run into an issue with this with the datetime and using the Form API #states. I described this in #2419131-58.
I do need to do some more changes to put back in the excluded/included dates as well. which I will start working on next.
Comment #21
realityloopReroll of #20 (wouldn't apply as part of composer.json for me)
@gordon any idea why the patch is drastically smaller than #19?
Comment #22
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commentedI removed all the versions of moment which were not being used.
Comment #23
thinkV CreditAttribution: thinkV commentedHave noticed a few other bugs @gordon, if you select monthly/weekly and choose some days, and save, and return to the form and select daily instead, it still applies the other rules.
Comment #24
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commented@thinkV yes I have noticed these bugs. I am planning to get these fixed soon, but this only effects the javascript and hopefully will not get posted to the server.
Comment #25
thinkV CreditAttribution: thinkV commentedthey don't get posted to the server @gordon however the results do not represent the settings saved, ie. editing the page draft will display the wrong information.
Comment #26
gordon CreditAttribution: gordon at Heydon Consulting for Deloitte Digital commented@thinkV yes I know and I am still working on this patch to get it all built correctly and for the js to work like the server side.
Comment #27
realityloopUpated to add a fix for dates that were strings instead of date objects, was throwing error in line 338 of DateRecurRRule.php
Comment #28
borisson_I haven't tested this yet, but I had some nitpicks from just reading the code.
Needs newline
This comment should either be removed or something should be written here.
Needs to start with a Capital and end with a period.
Needs newline
This is a javascript library, right? I don't think we can get those via composer. At least not with a default setup. It's possible only when extending composer to also do front-end packages.
This should be removed from composer.json and committed (if the license allows it) or fixed in another way.
This needs to respect 80 cols rule and the comment should be before the actual action. So:
This comment should be expanded, to have an @return statement and it should also start with uppercase.
Space after comma (H:i:s', $date)
Needs to respect 80 cols rule.
This line is really long and hard to understand, can we extract this variable and make it simpler by not using an inline if here?
This doesn't look right.
80 cols
Needs a docblock.
Needs a docblock
I think I had to read this line 4 times before I understood what's going on in here :D. Looks real nice though, good work!
This is very, very personal, but I dislike setting a variable in an if statement, can this be refactored to be something like this.
This improves readability, is stricter and less prone to others (espcially me ;)) fucking up (by thinking that it should be 2*=, changing that and everything breaking)
/s/checkboxes/rrule-byday-pos-wrapper/
/s/radios/rrule-end/ ?
Needs newline
Comment #29
borisson_Back to needs work per #28
Comment #30
chOP CreditAttribution: chOP at Deloitte Digital, Technocrat commentedI'm uploading a new patch, re-rolled against the current branch and addressing many of the issues listed. This patch also fixes
Comment #31
chOP CreditAttribution: chOP at Deloitte Digital, Technocrat commentedOMG, same names used in the files, that was stupid.
My apologies. Second patch and interdiff are correct ones, in spite of the duplicate names. I found an error in the JavaScript for a data attribute and corrected it.
It's too late now to rename the patch files, now they're uploaded with an incorrect comment number.
Comment #32
sleepingmonkPatch from #31 mostly works. Thanks all!
There are two issues I've noticed so far when selecting "Monthly". It will ignore the Month selection but save the Day selection.
i.e.
If I choose Day: Sunday and Month: Aug, Oct
Summary: every August and October on Sunday
RRule: FREQ=MONTHLY;BYDAY=SU;BYMONTH=8,10
The result of saving is repeat on every Sunday, every month. The month is ignored.
Editing the node again shows the month(s) are not selected and the Summary does not show a month selection.
Summary: On the Sunday each month at 22:59
RRule: FREQ=MONTHLY;BYDAY=SU
The second thing as a comment about the summary. Should the summary read [day] in [months] instead?
Summary: every Sunday in August and October
Comment #33
sleepingmonkAlso noticed Summary time is way off: Set 00:00:00, but it shows 23:48. Just in the summary. The data is saved correctly.
Comment #34
joelpittetCan someone explain the need for the moment library dependency? I see it's called twice, once for the
moment.ISO_8601
standard and the other for the format.I know there's not a consistent mechanism for including libraries in Drupal with a contrib module but having it as an external library would be ideal so it doesn't conflict with other projects (hopefully) using the same library.
Comment #35
MrPaulDriver CreditAttribution: MrPaulDriver commentedGood work; this is a big improvement all round.
As with the D7 Date module and Option to hide end date, keeping time, imposing a hard requirement for an end date is undesirable. I note that alpha 4 version does not require a time, although the input field remains visible, but this seems to have been overlooked with this patch.
Like D7 Date, I do think the option to hide the time field would make for the best UX and compatibility with a good third party date picker would round it off nicely.
Comment #36
shortspoken CreditAttribution: shortspoken commentedI'm very interested in testing the patch but it does not apply to the current dev version of date_recur.
Comment #37
sjpeters79 CreditAttribution: sjpeters79 commentedA bunch of things have changed in the newest dev version so it'll take time to refactor.
Comment #38
dpiComment #39
dpiAs noted above many things have changed since the last round of work on patches here. Before going further I'd encourage working on the widget in a new project, similar to the other widget issue: #2933796-21: [Ideas] Add new Drupalized widget. Notably dependencies like rrule.js are no longer in the main project so theyd need to be re-introduced.
Theres good work here, keep it going!
Comment #40
dpiThere seems to be little momentum or interest in this issue, so closing.