Drupal 8 Version?

Created on 12 December 2017, over 6 years ago
Updated 5 January 2024, 6 months ago

Has anyone talked about converting this module to D8?

πŸ“Œ Task
Status

Active

Version

1.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States safetypin Memphis, Tennessee

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands Bigbozz

    Can you please give an update of the migration to D8/9/10? I used this module on my old D7 site and it is/was very useful. For my new site I hope that you can make a D10 version of it. That would solve some problems for me. Or is there any alternative that I don't know yet?

  • πŸ‡¬πŸ‡§United Kingdom fonant

    Hi there, development stopped while the Rules module, which this module depends on, was ready for Drupal 8 and later.

    Looks like that's nearly the case, I'll have a look at what changes are needed here.

  • πŸ‡ΊπŸ‡ΈUnited States safetypin Memphis, Tennessee

    So, my issue was that I wanted a node to be created automatically, once per day, and I was able to create a custom module that creates a custom cron task that does this in code. It is two files. If you can figure out how to do what you want to do in code, then you can replace the contents of the if (REQUEST_TIME >= $next_execution) block below:

    once_per_day.info.yml:

    name: Once per Day
    type: module
    description: A custom module to automate daily node creation.
    core_version_requirement: ^9.2 || ^10
    package: Custom
    dependencies:
      - drupal:node
    

    once_per_day.module:

    
    use \Drupal\node\Entity\Node;
    
    /**
     * Implements hook_cron().
     *
     * We implement hook_cron() to do "background" processing. It gets called every
     * time the Drupal cron runs. We then decide what has to happen in response.
     *
     * In this example, we log a message after the time given in the state value
     * 'cron_example.next_execution'. Then we update that variable to a time in the
     * future.
     */
    
    function once_per_day_cron() {
      // We access our configuration.
      $cron_config = \Drupal::configFactory()->getEditable('once_per_day.settings');
    
      // 86400 seconds = 1 Day
      $interval = $cron_config->get('interval');
      $interval = !empty($interval) ? $interval : 60;
    
      // We usually don't want to act every time cron runs (which could be every
      // minute) so keep a time for the next run in the site state.
      $next_execution = \Drupal::state()->get('once_per_day.next_execution');
      $next_execution = !empty($next_execution) ? $next_execution : 0;
    
      if (REQUEST_TIME >= $next_execution) {
        $node = Node::create([
          'type'  => 'once_per_day',
          'title' => date('F j, Y', REQUEST_TIME) // date_iso8601(REQUEST_TIME)
        ]);
        $node->save();
        \Drupal::logger('once_per_day')->notice('once_per_day ran');
        \Drupal::state()->set('once_per_day.next_execution', strtotime('tomorrow +7 hours'));
      }
    }
    
    
Production build 0.69.0 2024