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.
Problem/Motivation
Add a base for the administration form. This will include things such as enabling and disabling notifications from certain content types. At the moment, not all features need to be present, but a strong base is needed for future expansion.
Proposed resolution
Add the default admin form and start adding the ability to set and store the values for digests.
Remaining tasks
- Create admin form to edit digest settings
- Add basic saving functionality for these settings. (needs to be extensible, perhaps entities)
- Set up some basic configuration info (Send from address, etc.)
User interface changes
This will add an admin form. UI should be determined by the theme so as long as the form is not a mess this should not be an issue.
Comment | File | Size | Author |
---|---|---|---|
#20 | digest-3152692-20.patch | 32.47 KB | DerekCresswell |
#20 | interdiff-3152692-20.txt | 12.31 KB | DerekCresswell |
Comments
Comment #2
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedComment #3
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedIn progress, will mark as 'Needs review' later.
Comment #4
joshmillerI've not seen someone use dependency injection like this before. Where does it come from?
As discussed, we don't want content types in the config form.
Comment #5
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commented@joshmiller yeah, this was from yesterday, I'm switching this up as we speak.
The dependency injection style is a bit of a newer thing. People, myself included, complained about
__construct
functions having unwieldy long signatures. Turns out many see that function as unnecessary and some modules (like webform) are adopting it.It really is just removing an un-needed step in adding dependency injection. I used this in the 'weekly_digest' module as well. I can find some links to the discussion if you'd like.
Probably don't need to review this to deeply until I mark it as so because at the minute it's just bench marking progress.
Comment #6
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedHere is another day of progress. The main shape is here, mainly needs to fill out some values now.
Digests are going to be stored as Config Entities. These entities will contain info for each view, such as if it is active and how often to send it out.
Values needed :
* Send every, how long to wait between sends (borrow format from views Date.php options like "send every '3 days'")
** Hopefully have both that or the option of "every friday"
* Minimum needed, only send an email if there are more than X items in the view
* Might drop the 'send as' for now.
* Others?
Some config, like the from address, will just be stored per site.
Going to add the other current values to config tomorrow and make sure there is documentation where needed.
Comment #7
joshmillerComment #8
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI've added a test of the config form (More could probably be done if desired). Not entirely sure of the best way we can test the entities but that can come later or with suggestions.
As for the options added, I think it should stay rather small and simplistic for now. It's just got an on / off and a when to send string. For that I've just gone with the method of 'when to send' and allowed for multiple values. A 'send every x' really wouldn't bee to great of an idea. What would it be relative to? So ditched that.
Comment #9
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedOops, messed up that patch.
Comment #10
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI've added a little more testing. Some more advanced ones will take more time as I have not written those before.
Comment #11
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI've updated the Digest entity to be more inline with the standard way entities are written.
Comment #12
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedI don't have a strong opinion on injecting the container vs services. My first thought about it is that injecting the container would make it harder to test by making it harder to mock or otherwise control the service's dependencies in a test, but I don't know the arguments for or against it. I don't think webform doing it is means you should, though. For example, that module thought it was OK for an interface to have 103 public methods https://git.drupalcode.org/project/webform/-/blob/602b05c0e317c556dc162f....
This file needs to start with an `@file` docblock. See https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... and https://www.drupal.org/docs/develop/standards/api-documentation-samples#... for what that should look like (@file comments in .module files should describe the module's purpose).
Should this use the `administer digest settings` permission instead, and specify that it's an admin route?
You can't mix @inheritdoc with additional comments. {@inheritdoc} has to be the only line in the docblock. https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...
The value of #title should be translated too. There's a couple #titles that need this.
Don't mix sentences in one `t()` string, and keep markup out of that string except in circumstances where you need it to avoid splitting up one sentence. See https://www.drupal.org/docs/7/api/localization-api/localization-api-over..., and https://www.drupal.org/docs/7/api/localization-api/dynamic-strings-with-... and https://www.drupal.org/docs/7/api/localization-api/dynamic-or-static-lin.... The last one specifically talks about how to handle HTML with translatable strings. For the string you have, you'd want the "Views" heading to be one string and "Choose ... notifications." to be another, and the markup should not be part of the translatable string.
That string should be translatable.
It should also help fix the problem. "When to send" could be a really complex value. Besides having to figure out what a valid PHP date string is, the user might have multiple in there. It would help to say which part doesn't work.
It's possible for this error to be set multiple times. If you have three times in there, all invalid, you'd get this same message 3 times. It might be better to build a list of invalid
$dateStamp
s, then set the error once if the list is non-empty. Then the message can say something like what you have now, plus a list of which parts couldn't be parsed.In additional to syntax errors like using a date that can't be parsed, someone could make the logical error of not writing the schedule that they intended. It might be nice to have feedback about the schedule, such as showing the date and time that each string resolves to.
Overall, I don't like this way of managing the schedule at all, but that's better discussed after looking at the form element that this validation pertains to:
This is a super complex form element. Being a text field is simple, but that puts all the complexity on the user instead. Because of that, clear documentation is essential. This description is very good. I think it's missing an explanation of what time on Monday that example would be sent at, and whether you can have a daily or monthly schedule.
It would be a bit easier for the user if it didn't support multiple values this way, and had an "add another time" button to add a separate element for that. It'd also be easier if there were foolproof widgets for it, like selecting "monthly" followed by the day of the month and time, "weekly" followed by the day of the week and time, or "daily" followed by the time.
I think there should be a different format for the schedule - one that's more clearly defined and easier to understand than "whatever it is that PHP's strtotime comes up with". Cron expressions might be a better option. They still have the problem of being cryptic, but they're better defined and not PHP-specific. I'd try to make this form have friendlier widgets, then store the value in a cron format, and probably use something like https://github.com/dragonmantank/cron-expression.
Instead of one Digest per view and multiple schedules, I think you should have one schedule per Digest, and instead of having all the views on this page, saving/updating them all in one spot, you should have a page listing digests, and add/update/delete them individually. I made a drawing of what I mean by that: https://docs.google.com/drawings/d/1P6KNoNJxs98lysDyC-yumRQO-iafr5QCkH-d...
The two additional paragraphs should either be separated with a blank line or be one paragraph, wrapped as close to 80 characters as possible. Ie, "new entity is created. If an entity ..." instead of having a line break.
The value of send_at should not be a string except when it needs to be serialized. That is, in the config file it would be a string but when it's loaded it should be specific type. If there isn't an appropriate class in PHP's standard library, make one, call it DigestSchedule or whatever, and have
Digest::getSendAt
andDigest::setSendAt
use that type instead of strings.Comment #13
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI've gone through and made the first batch of changes. I'll now start working on improving the schedule setting as I think what you've put forward is a great idea.
Changes made :
* Fixed translation issues.
* Fixed documentation issues.
* Improved routing.
* PHPCS auto fixes, apparently mine was not running both Drupal and DrupalPractice before (it is now).
About the dependency injection, I am no wizard of Drupal. From my eyes, the method shown here is more concise and readable. I am unsure if there are hidden problems down the road. Do you believe we should switch to using
__construct
like usual? I will do a little more digging and discussing to see if more people have a say : ).Comment #14
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedPHPUnit seemed inconsistent, just going to remove the
_admin_route
as it isn't needed for these cases.Comment #15
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI've gone about adding the List Builder for the digests, much nicer than before.
The 'send_at' value is still the same as before. There might be some discussion if that should change now or wait a little bit. It might be more beneficial to continue with other parts of development and return to creating a nicer schedule field later.
If so, the verification needs to be adding back from before but, that's trivial.
Comment #16
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedI swear I'm going to de throne phpunit someday and show it who's boss.
changed core version requirement to `^8.8 || ^9`
Comment #17
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedAlright, I've added the basic when to send validation for now.
I've opened a new issue to address turning the value into a custom field. For now this can be reviewed (disregarding the current send_at) and commited.
Comment #18
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedSmart to make a new issue for the send_at stuff.
I still have a gripe about the digests' IDs. I don't like that they have to match the view. I think the main issue is that you're forced into having multiple schedules in one digest since you can't have two digests referencing the same view. But that's essentially getting back to the send_at discussion.
I don't think you can choose which display of the view to show, which might be an issue if someone wants to send one display on one schedule and another on a different schedule. Ie, one might want their blog newsletter view to be one view with a 'weekly' display that filters by blogs from the last 7 days and a 'monthly' display that filters by the last 30 days, rather than having two separate views that are nearly identical. But that's probably best left as a separate issue too.
Is it too late to discuss not integrating with views? If you selected a block to include in the email instead of a view, people could still send views by adding a block display to the view, and it would be possible for people to get creative by sending any block on a schedule, which could be a custom one that pulls in content from wherever, or shows some other kind of regular report.
I like it a lot more with the list of entities separate from the configuration form. I found a few nitpicky things that could be addressed here.
You're not telling anyone anything they didn't already know there. @file should describe the
https://www.drupal.org/docs/develop/standards/api-documentation-samples#... has an example and https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... has another
Some other examples are commerce.module's "Defines common functionality for all Commerce modules." and user.module's "Enables the user registration and login system.".
For documenting classes, leave out "Used to" and say "Builds lists of available Digests."
The permission should match the permission's machine name, not its title. Make it "administer digest settings".
There's a few #titles in the forms that need to use
t()
.Comment #19
joshmillerOoooh. I second Travis' idea for using blocks as an abstraction layer. I think this would be worth the effort in replacing the views integration. It also opens the door for fieldable blocks, and many other possibilities.
Comment #20
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedSwitched to block based digests.
Comment #21
travis-bradbury CreditAttribution: travis-bradbury at Acro Commerce commentedLooks good to me.
Comment #23
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commentedCommitted, thanks guys.
Comment #24
DerekCresswell CreditAttribution: DerekCresswell as a volunteer and at Acro Commerce commented