Add support for macros #329
No reviewers
Labels
No labels
Component: User interface
Component: Wymeditor
Help wanted
Level: Difficult
Level: Easy
Level: Moderate
Pagetype: Festival
Pagetype: Mailinglist
Pagetype: Peer reviewed article
Pagetype: Text
Privacy GDPR AVG
status: has conflicts
Status: Needs changes
Status: Needs discussion
Status: Needs review
Status: Ready to merge
Status: Waiting for response
Type: Bug
Type: Enhancement
Type: Question
Usecase: De Stadsbron
Usecase: Koppelting
Usecase: MeetjeStad
Value: Coders
Value: Security
Value: Users
Value: Visitors
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
harmen/hypha!329
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "macros"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is still a WIP, just wanted to share my progress so far.
I've now added a page list macro, which can be used to generate e.g. a homepage with recent articles, or a tag-based index page. Used e.g. like:
This probably still needs some more helper methods to make accessing macro options easier and more robust (though there is already some error checking in place).
I think this is ready for merging now. I've used the pagelist macro to automate the homepage lists (both the audio/video as well as the list of normal articles) at http://test.destadsbron.nl/nl/home
Review of the code, but also the test site is welcome.
I added some more options to the pagelist macro, it should now be suitable to be used on e.g. De Stadsbron to generate the homepage, tag pages and timeline/archive pages. I'll probably deploy this code already, while waiting for review and merging.
@ -0,0 +80,4 @@* @param string $name The name of the attribute to get* @return DateTime | null*/protected function getDateTimeAttribute($name, $format, $errorFormat, $default = null) {I'm a bit surprised to see this function here. I wouldn't expect it to be part of the base class of a macro, seems a bit specific. But perhaps I'm missing something?
@ -0,0 +136,4 @@$validTypes = hypha_getDataTypes();foreach ($pageTypes as $type) {if (!array_key_exists($type, $validTypes))throw new UnexpectedValueException("Invalid page type: $type. Valid options are: " . implode(', ', array_keys($validTypes)));Do we want to abort or fail with a message? If in the future one page type is removed/changed then the entire macro becomes broken. I'm thinking about when a user in a few years looks back at a page made a few years before that,
@ -0,0 +136,4 @@$validTypes = hypha_getDataTypes();foreach ($pageTypes as $type) {if (!array_key_exists($type, $validTypes))throw new UnexpectedValueException("Invalid page type: $type. Valid options are: " . implode(', ', array_keys($validTypes)));This exception is caught further up, so it's just the macro that fails, not the entire page. That seems to me the safest and clearest way to fail, you could ignore the missing value and render something with a warning on top, but then it's really easy to miss the warning, so I think I'd prefer to just have the macro fail completely.
Looks great!
@ -0,0 +125,4 @@// Include private pages only when logged in and enabled// TODO: Better checking of option values (and maybe// allow Yes/true/TrUe/etc.)I think there is a typo here. :-)
@ -0,0 +80,4 @@* @param string $name The name of the attribute to get* @return DateTime | null*/protected function getDateTimeAttribute($name, $format, $errorFormat, $default = null) {Well, I could imagine other macros that also need date/time parameters, so this is just a helper function to access such attributes/arguments. I also anticipate other helper functions for parsing other types of arguments, but I haven't had the need yet I guess.
Maybe it would make sense to move the actual parsing code to a more general place, and then here just call that?
@ -0,0 +80,4 @@* @param string $name The name of the attribute to get* @return DateTime | null*/protected function getDateTimeAttribute($name, $format, $errorFormat, $default = null) {I'm going to leave this for now and merge this. We can always move this code later if that turns out better (e.g. when we add a few more macros).
@ -0,0 +80,4 @@* @param string $name The name of the attribute to get* @return DateTime | null*/protected function getDateTimeAttribute($name, $format, $errorFormat, $default = null) {Cool :)
@ -0,0 +125,4 @@// Include private pages only when logged in and enabled// TODO: Better checking of option values (and maybe// allow Yes/true/TrUe/etc.)Reading it again, I think that this is not a typo, but I meant to say that checking should be case insensitive :-)
Rebased on top of master, and I added two more fixes:
With that, I'm merging this.