From e4946675994b5198e2f17d2b0a08e57f6bd4f69f Mon Sep 17 00:00:00 2001
From: Karan Garg <48285-KaranGarg@users.noreply.drupalcode.org>
Date: Thu, 16 Jan 2025 14:56:17 +0000
Subject: [PATCH 1/2] Update scheduler.module. The constraints were not
 executing in a particular scenario.

---
 scheduler.module | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scheduler.module b/scheduler.module
index c6d74aa0..fc1dfb0a 100644
--- a/scheduler.module
+++ b/scheduler.module
@@ -803,6 +803,27 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) {
   return $fields;
 }
 
+/**
+ * Implements hook_entity_bundle_field_info_alter().
+ */
+function scheduler_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
+  /* This is necessary for content types where the title label is changed from the default "Title" to something else.
+   * In this case, the field are considered a bundle field and the constraint must be added here.
+   * This is expected (not a Drupal bug); there is some info here: https://www.drupal.org/project/drupal/issues/3193351
+   */
+  $entity_types = \Drupal::service('scheduler.manager')->getPluginEntityTypes();
+
+  if (in_array($entity_type->id(), $entity_types)) {
+    if (!empty($fields['publish_on'])) {
+      $fields['publish_on']->addConstraint('SchedulerPublishOn', []);
+    }
+
+    if (!empty($fields['unpublish_on'])) {
+      $fields['unpublish_on']->addConstraint('SchedulerUnpublishOn', []);
+    }
+  }
+}
+
 /**
  * Implements hook_action_info_alter().
  */
-- 
GitLab


From 67a91edf4a327cbb95056a75766ecb3a071f40d9 Mon Sep 17 00:00:00 2001
From: Karan Garg <48285-KaranGarg@users.noreply.drupalcode.org>
Date: Thu, 16 Jan 2025 16:05:36 +0000
Subject: [PATCH 2/2] Fixed PHP CodeSniffer Issues.

---
 scheduler.module | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/scheduler.module b/scheduler.module
index fc1dfb0a..f207c566 100644
--- a/scheduler.module
+++ b/scheduler.module
@@ -807,10 +807,11 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) {
  * Implements hook_entity_bundle_field_info_alter().
  */
 function scheduler_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
-  /* This is necessary for content types where the title label is changed from the default "Title" to something else.
-   * In this case, the field are considered a bundle field and the constraint must be added here.
-   * This is expected (not a Drupal bug); there is some info here: https://www.drupal.org/project/drupal/issues/3193351
-   */
+  // This is necessary for content types where the title label is changed from
+  // the default "Title" to something else. In this case, the field are
+  // considered a bundle field and the constraint must be added here. This is
+  // expected (not a Drupal bug).
+  // Additional info: https://www.drupal.org/project/drupal/issues/3193351.
   $entity_types = \Drupal::service('scheduler.manager')->getPluginEntityTypes();
 
   if (in_array($entity_type->id(), $entity_types)) {
-- 
GitLab