I'm using the Scheduler module to schedule when certain nodes get published&unpublished. Now, they are set to be "Promoted to the front page" and even after the Scheduler unpublishes the content, it stays promoted to the front page where it still appears and leads to a dead link.

How can I automatically set the content to also get un-promoted from the front page when it gets unpublished?

I have also submitted s upport request here: http://drupal.stackexchange.com/questions/192135/how-can-i-only-allow-pu... - I will update this posting accordingly to keep the two threads in sync.

Added Comment on stackexchange:
02/20/2016 - 11:55am– mchar
It depends on the way that you have developed your front page. Is it a view, a panel, a custom page, something else ?

Edit from myself to the original post:
My front page is the default front page that comes with Drupal 7. I understand, that if I had my own view, I could select what kind of content gets displayed. But how can I do this with the Drupal 7 news feed?

02/20/2016 - 12:40pm– mchar
As far as I know scheduler module is not responsible for promoting or not nodes to the frontpage, so you have to go with a custom solution.

Try to implement hook_node_presave as follows:

/**
 * Implements hook_node_presave().
*/ 
function my_module_node_presave($node) {
  $was_published = !empty($node->original->unpublish_on);
  $now_is_unpublished = empty($node->unpublish_on);

  if (!$node->is_new && $was_published && $now_is_unpublished) {
    $node->promote = 0;
  }
}

Hope that helps!

02/20/2016 - 1:20pm– mchar
Well, you have to create your own module and place that code in your module's .module file. Don't ever try to hack contrib modules or the core, for many reasons! Yes, the hook_node_presave will fire whenever the cron runs. Here is a guide to create your first module, don't be scared, it's really easy.

Comments

cerr created an issue. See original summary.

cerr’s picture

Issue summary: View changes
cerr’s picture

Added Comment on stackexchange:
It depends on the way that you have developed your front page. Is it a view, a panel, a custom page, something else ?mchar

Edit from myself to the original post:
My front page is the default front page that comes with Drupal 7. I understand, that if I had my own view, I could select what kind of content gets displayed. But how can I do this with the Drupal 7 news feed?

cerr’s picture

Issue summary: View changes
cerr’s picture

Issue summary: View changes
cerr’s picture

Issue summary: View changes
cerr’s picture

Issue summary: View changes
jonathan1055’s picture

Hi cerr,
I am surprised you are having this problem. Yes, Scheduler will only change the node status. However, when the node becomes unpublished it should automatically disappear from your front page because the core front page views filetr out unpublished nodes. I have just tried this with a fresh install of D7.42 and Scheduler 7.x-1.3. The node was showing on my front page, it was unpublished by Scheduler and the no longer showed. The promote flag was still set on, but status was off. The same thing happens whether you have /node as your front page or leave it blank for the "default content feed" as per the setting in admin/config/system/site-information. Do you have your front page content cached in some way so that it needs refreshing when nodes become unpublished?

If you really do need to set promote off when a node is unpublished, rather than use hook_node_presave() it may be better to use one of the hooks we provide with the scheduler module. Your hook_node_presave() will be executed when any node is editted and saved, every time, even the node types which are not enabled for Scheduler. You may find you have to add more code to limit the processing to just what you want. With Scheduler we provide hook_scheduler_api($node, $action)

/**
 * This allows other modules to implement hook_scheduler_api($node, $action).
 *
 * @param object $node
 *   The node object.
 * @param string $action
 *   The action being performed, either 'pre_publish', 'publish',
 *   'publish_immediately', 'pre_unpublish' or 'unpublish'.
 */

So you would create mymodule_scheduler_api($node, $action) and then test for $action == 'unpublish' and change the node promote value accordingly.

A custom module is very useful to do this kind of thing, however, if you don't want to do that, you can use the Rules module. Scheduler provides good integration with Rules, which will allow you to set an 'unpromote' node action whenever Scheduler unpublishes a node.

Hope that helps.

Jonathan

jonathan1055’s picture

Title: unpromote node when it gets unpublished. » Unpromote node when it gets unpublished.
Status: Active » Closed (outdated)
Related issues: +#1092934: Scheduled promotion / demotion from Front page

Take a look at #1092934-17: Scheduled promotion / demotion from Front page where I have given the full code for un-promoting from front page using Scheduler.

Closing this issue now, as it has been two months with no response.

jonathan1055’s picture

Status: Closed (outdated) » Closed (works as designed)

Wrong status. 'Outdated' is used when the module version is unsupported.