1
1
<?php
2
2
3
3
use Drupal\Core\Entity\EntityInterface;
4
+ use Drupal\os2uol_domain\DomainConfigHelper;
4
5
5
6
/**
6
7
* Implements hook_cron().
@@ -14,16 +15,44 @@ function os2uol_moderation_cron() {
14
15
* Implements hook_content_moderation_notification_mail_data_alter().
15
16
*/
16
17
function os2uol_moderation_content_moderation_notification_mail_data_alter(EntityInterface $entity, array &$data) {
17
- // Get the active domain ID.
18
- $domain_id = \Drupal::service('domain.negotiator')->getActiveId();
19
- $config = \Drupal::config('os2uol_settings.settings');
18
+ // Get the workflow associated with the entity.
19
+ $workflow = \Drupal::service('content_moderation.moderation_information')->getWorkflowForEntity($entity);
20
+ if ($workflow->id() !== 'application') {
21
+ return;
22
+ }
23
+
24
+ // Use the DomainConfigHelper to fetch domain-specific configuration.
25
+ $config_helper = \Drupal::service('os2uol_domain.config_helper');
26
+ $domain = \Drupal::service('domain.negotiator')->getActiveDomain();
27
+
28
+ // Validate that a valid domain was retrieved.
29
+ if (!$domain) {
30
+ \Drupal::logger('os2uol_moderation')->error('Unable to load the active domain.');
31
+ return;
32
+ }
33
+
34
+ // Fetch the domain-specific configuration.
35
+ $domain_config = $config_helper->getDomainConfig('os2uol_settings.settings', $domain);
36
+
37
+ // Log the domain config for debugging purposes.
38
+ \Drupal::logger('os2uol_moderation')->info('Using domain config: @config for domain: @domain_id', [
39
+ '@config' => print_r($domain_config->getRawData(), TRUE),
40
+ '@domain_id' => $domain->id(),
41
+ ]);
20
42
21
43
// Default fallback email address.
22
- $fallback_email = 'info @os2udoglaer.dk';
44
+ $fallback_email = 'fallback @os2udoglaer.dk';
23
45
24
46
// Retrieve the configured "From" and "Reply-To" email for the active domain.
25
- $from_email = $config->get('from_reply_to_email') ?: $fallback_email;
26
- $reply_to_email = $config->get('from_reply_to_email') ?: $fallback_email;
47
+ $from_email = $domain_config->get('from_reply_to_email') ?: $fallback_email;
48
+ $reply_to_email = $domain_config->get('from_reply_to_email') ?: $fallback_email;
49
+
50
+ // Log the resolved emails for debugging purposes.
51
+ \Drupal::logger('os2uol_moderation')->info('Resolved From and Reply-To emails: From: @from, Reply-To: @reply_to for domain: @domain_id', [
52
+ '@from' => $from_email,
53
+ '@reply_to' => $reply_to_email,
54
+ '@domain_id' => $domain->id(),
55
+ ]);
27
56
28
57
// Set the "From", "Reply-To", and "Return-Path" headers.
29
58
$data['headers']['From'] = $from_email;
@@ -34,6 +63,27 @@ function os2uol_moderation_content_moderation_notification_mail_data_alter(Entit
34
63
\Drupal::logger('os2uol_moderation')->info('Using From and Reply-To addresses: @from, @reply_to for domain: @domain_id', [
35
64
'@from' => $from_email,
36
65
'@reply_to' => $reply_to_email,
37
- '@domain_id' => $domain_id ,
66
+ '@domain_id' => $domain->id() ,
38
67
]);
39
68
}
69
+
70
+ /**
71
+ * Implements hook_views_query_alter().
72
+ */
73
+ function os2uol_moderation_views_query_alter($view, \Drupal\views\Plugin\views\query\QueryPluginBase $query) {
74
+ // Target the specific view and display.
75
+ if ($view->id() === 'workbench_recent_content' && $view->current_display === 'embed_1') {
76
+ // Ensure the query is SQL-based.
77
+ if ($query instanceof \Drupal\views\Plugin\views\query\Sql) {
78
+ // Add an explicit WHERE clause to exclude "trash" moderation state.
79
+ $query->addWhereExpression(0, "
80
+ NOT EXISTS (
81
+ SELECT 1
82
+ FROM {content_moderation_state_field_data} cms
83
+ WHERE cms.content_entity_id = node_field_data.nid
84
+ AND cms.moderation_state = 'trash'
85
+ )
86
+ ");
87
+ }
88
+ }
89
+ }
0 commit comments