Need to set publish on date for tomorrow always

Created on 19 April 2023, over 1 year ago

HI need to add publish on date for tomorrow always. This is for article submission. How to do that.. can you guide me the way

💬 Support request
Status

Needs review

Version

2.0

Component

User Interface

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rajitha.somarathna
  • Assigned to apatel0325
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India apatel0325

    function mymodule_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'node_article_form') {
    // Set the "Publish on" date to tomorrow's date
    $form['options']['status']['scheduled']['publish_on']['#default_value'] = date('Y-m-d', strtotime('+1 day'));
    }
    }

    @rajitha.somarathna Can you please try with the above code?

  • This is great.. for do this what is the path for the function? I have no idea to change which place to change the code. @apatel0325

  • 🇮🇳India apatel0325

    Create new custom module and in .module file you have to write above function.

  • 🇮🇳India Manoj Raj.R Chennai

    Above looks good to me.

  • I'm using the 2.0RC version of Scheduler, and have tried this code in a custom module per your suggestion (in my case, setting the unpublish date to two years in the future).

    It isn't working for me. Not sure what I'm doing wrong? Here's the code from my .module file:

    function mymodule_form_alter(&$form, &$form_state, $form_id) {
        if ($form_id == 'node_events_form') {
            // Set the "Publish on" date to two years from now
            $form['options']['status']['scheduled']['unpublish_on']['#default_value'] = date('Y-m-d', strtotime('+2 years'));
        }
    }
    
Production build 0.71.5 2024