diff --git a/scheduler.module b/scheduler.module index c6d74aa09dc6cef0dbde16e52faf10e456a74284..f207c5663cdf4d5e11138aef4f9822d0ab36e27f 100644 --- a/scheduler.module +++ b/scheduler.module @@ -803,6 +803,28 @@ 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). + // 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)) { + 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(). */