diff --git a/scheduler.module b/scheduler.module index e246af3..4c4fb10 100644 --- a/scheduler.module +++ b/scheduler.module @@ -399,6 +399,20 @@ function _scheduler_entity_type_form_alter(&$form, FormStateInterface $form_stat ], ], ]; + + // Option to allow direct publishing even if scheduling is set. + $form['scheduler']['publish']['scheduler_publish_direct'] = [ + '#type' => 'checkbox', + '#title' => t('Allow direct publishing'), + '#default_value' => $type->getThirdPartySetting('scheduler', 'publish_direct', $config->get('default_publish_direct')), + '#description' => t('Allow direct publishing even if the content is already scheduled.'), + '#states' => [ + 'visible' => [ + ':input[name="scheduler_publish_enable"]' => ['checked' => TRUE], + ], + ], + ]; + if ($contentEntityType->isRevisionable()) { $form['scheduler']['publish']['scheduler_publish_revision'] = [ '#type' => 'checkbox', @@ -551,6 +565,7 @@ function _scheduler_form_entity_type_form_builder($entity_type, $type, &$form, F $type->setThirdPartySetting('scheduler', 'publish_past_date', $form_state->getValue('scheduler_publish_past_date')); $type->setThirdPartySetting('scheduler', 'publish_past_date_created', $form_state->getValue('scheduler_publish_past_date_created')); $type->setThirdPartySetting('scheduler', 'publish_required', $form_state->getValue('scheduler_publish_required')); + $type->setThirdPartySetting('scheduler', 'publish_direct', $form_state->getValue('scheduler_publish_direct')); $type->setThirdPartySetting('scheduler', 'publish_revision', $form_state->getValue('scheduler_publish_revision')); $type->setThirdPartySetting('scheduler', 'publish_touch', $form_state->getValue('scheduler_publish_touch')); $type->setThirdPartySetting('scheduler', 'show_message_after_update', $form_state->getValue('scheduler_show_message_after_update')); @@ -937,10 +952,19 @@ function scheduler_entity_presave(EntityInterface $entity) { // Check that other modules allow the action on this entity. $publication_allowed = $scheduler_manager->isAllowed($entity, 'publish'); - // Publish the entity immediately if the publication date is in the past. - $publish_immediately = $scheduler_manager->getThirdPartySetting($entity, 'publish_past_date', $config->get('default_publish_past_date')) == 'publish'; + // Retrieve entity settings for Scheduler + $publish_past_date_immediately = $scheduler_manager->getThirdPartySetting($entity, 'publish_past_date', $config->get('default_publish_past_date')) == 'publish'; + $direct_publish_allowed = $scheduler_manager->getThirdPartySetting($entity, 'publish_direct', $config->get('default_publish_direct')); + $publish_status = $entity->get('status')->value; + $publish_on_time = $entity->publish_on->value; + + // Determine if the publication date is in the past + $past_due = $publish_on_time <= $request_time; + + // Determine if the entity should be published immediately based on past date or direct publishing + $publish_immediately = ($publish_past_date_immediately && $past_due) || ($direct_publish_allowed && $publish_status); - if ($publication_allowed && $publish_immediately && $entity->publish_on->value <= $request_time) { + if ($publication_allowed && $publish_immediately) { // Trigger the PRE_PUBLISH_IMMEDIATELY event so that modules can react // before the entity has been published. $scheduler_manager->dispatchSchedulerEvent($entity, 'PRE_PUBLISH_IMMEDIATELY'); @@ -1255,6 +1279,7 @@ function scheduler_migrate_prepare_row(Row $row, MigrateSourceInterface $source, 'scheduler_publish_enable_' . $row->getSourceProperty('type'), 'scheduler_publish_past_date_' . $row->getSourceProperty('type'), 'scheduler_publish_required_' . $row->getSourceProperty('type'), + 'scheduler_publish_direct_' . $row->getSourceProperty('type'), 'scheduler_publish_revision_' . $row->getSourceProperty('type'), 'scheduler_publish_touch_' . $row->getSourceProperty('type'), 'scheduler_unpublish_enable_' . $row->getSourceProperty('type'),