Closed (fixed)
Project:
Scheduler
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
10 Apr 2013 at 17:29 UTC
Updated:
10 Aug 2013 at 17:41 UTC
Jump to comment: Most recent file
Comments
Comment #1
pfrenssenComment #2
jonathan1055 commentedHi pfrenssen
This is a really nice idea, and so simple to implement! I did not know that implementations of hook_TYPE_alter() could be used to alter anything. The documentation talks about using it to alter content types and forms, but of course, if a module implements it corrctely then there is no reason that we cannot utilise the power of drupal_alter to do anything.
Your patch does not use the 4th parameter of drupal_alter. Can you think of anything that we could usefully pass for $context2?
Also, could you post your current implementation of hook_scheduler_node_list_alter, for interest, and to allow others to see why this is such a nice idea. I will also write my own hook_scheduler_node_list_alter to test your patch.
Jonathan
Comment #3
pfrenssenYes
drupal_alter()is awesome, it makes interoperability between modules really easy. I don't think we need to use the 4th parameter, this is used to pass additional contextual information, but we basically have only two use cases: publishing and unpublishing, and these can be passed in one variable.My implementation is based on #1955938: Publish only "approved" nodes . I will continue on that issue soon and post a patch when it is ready, but the basic idea is as follows:
Comment #4
jonathan1055 commentedHi,
Just trying this, and I get
As you might have guessed, this is the call to drupal_alter, which I implemented as copied from your example above. $nids is an array but I presume you had this working, so is there something I need to do to enable it?
Just realised I am still using D7.17 so I will upgrade to 7.22 then test again.
Jonathan
Comment #5
jonathan1055 commentedThink I've fixed it. Nothing to do with old drupal version. The code in your patch needs to be:
ie the context should be a variable not a fixed string.
Jonathan
Comment #6
jonathan1055 commentedJust discovered that the variable $context is already used in _scheduler_publish() and _scheduler_unpublish() - so it would need to be a different name, eg $context1, or $scheduler_context or something.
Comment #7
jonathan1055 commentedForgot to change the status as the patch needs amending.
My tests are working now and this will be a very useful (and powerful) addition. Thanks for the idea pfrenssen.
Comment #8
pfrenssenThanks for the review! Your remarks look valid, it should pass a variable instead of a fixed string.
I will update the patch when I get on the train home, in a few hours.
Comment #9
pfrenssenOk I have updated the patch, this should work better. I have opted for the variable name
$action, this is consistent withhook_scheduler_api()andhook_scheduler_nid_list().Comment #10
jonathan1055 commentedTested the patch in #9 and it works. Yes, $action is a good choice.
Just one minor question - we already implement the function hook_scheduler_nid_list() so is hook_scheduler_node_list_alter() ok? I guess the word 'alter' makes it distinct enough, just. I thought I would mention it now, as we will never be able to change it after other users/modules start implementing their hooks.
I am kind-of ok with the name as it stands, but would like you to think about it, and also to get the opinion of the co-maintainers and others.
Jonathan
Comment #11
pfrenssenGood idea, that would be more consistent. I have renamed the alter hook to
hook_scheduler_nid_list_alter()and improved the documentation a bit.Comment #12
jonathan1055 commentedExcellent. Reviewed and tested. Rick has already just made a 7.x-1.1 but hopefully release 1.2 will not be too far away.
To add to your example in #3 here is what I used to test the hook:
Thought you might be interested in the idea of pushing back the publish time. I have a calendar view of upcoming nodes to be published and the ones which were blocked were showing as upcoming in the past, which looked all wrong. This way, if the node is rejected it is continually pushed forward until the author is accepted.
Jonathan
Comment #13
pfrenssenNice example! I am now also working on a real life application in #1955938: Publish only "approved" nodes .
Comment #14
pfrenssenThis creates an interesting problem. As other modules can now prevent content from being scheduled, they should also have the possibility to suppress the status message that is shown when scheduled content is saved:
In my use case, scheduled content will only be published if it has been approved by an administrator. So when regular content editors submit a node, they should not receive the above message, since it is not sure at that point if the content will be approved for publication.
I saw that this message is output in
hook_node_presave(), which is also not really the right place for this as it fires on everynode_save(). More appropriate would be to move this tohook_node_submit(), so that it would only show when nodes are saved through submitting the node form.Comment #15
jonathan1055 commentedYes there might be better ways to put out that message, and also allow its content to be modified by modules which implement hook_scheduler_nid_list_alter()
Maybe that same hook function could be called directly with a specific parameter, instead of having a different hook to implement? Plenty of options to play with.
Maybe, as this issue is RTBC I would suggest opening a new one, not to delay this patch?
Comment #16
pfrenssenHere is an idea how to solve it. Not yet tested.
Comment #17
jonathan1055 commentedHi,
Had a look at your patch, and I've got a few things to discuss
The line
$node->status = 0which ensures a scheduled node does not get immediately published is included in that conditional block. You are affecting too much here, it is only the message that you want to suppress.The first line should be $key = $action . '_on';
return $resultat the end.Nice work though. It will be good when done.
Comment #18
pfrenssenThanks for the remarks! Sorry for the lack of explanation with the patch, I was in a hurry to catch my train and quickly put my work in progress online before leaving.
I think this is actually completely covered. The original check was too broad. The
is_numeric($node->publish_on)check was not needed because the preceding code in that function already ensures that this is either 0 or a number representing unix time. Andisset($node->publish_on) && $node->publish_on != ''can be rewritten as!empty($node->publish_on), which is covered by <code>scheduler_is_scheduled().Yesterday I looked for a way to do this in one hook, but it did not seem to be possible to allow all the use cases in the summary:
But yeah this needs to be documented more clearly, both in the code, and preferably also in a scheduler.api.php file with some examples.
Good points, will address these.
I agree, I will update the summary to limit the scope of this issue to reordering/limiting the node list and create a new issue for the new hook. The latest patch is trying to solve two problems at once, that is never good.
Comment #19
pfrenssenI have updated the issue summary to reduce the scope to only reordering / limiting the list of scheduled nodes, and have created new issues for the second hook and the API documentation:
Comment #20
pfrenssenThis is the exact same patch from #11 that has been RTBC'd by jonathan1055 in #12, so setting status back to RTBC.
The approach discussed in comments #14 to #18 has been moved to a separate issue: #1979460: Allow other modules to prevent scheduled nodes from being published / unpublished
Comment #21
rickmanelius commentedHi pfrenssen,
Thanks for your contribution and being willing to split this off into different issues. This has been committed:
http://drupalcode.org/project/scheduler.git/commitdiff/34ea8a2?hp=0d0be0...
-Rick
Comment #22.0
(not verified) commentedReduced scope