Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions notify_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ function _notify_entity_trigger_event($event, Drupal\Core\Entity\EntityInterface

if ($value = $config->get($key)) {
if ($value[$event]) {
// If status is set, check if it matches condition
if (isset($value['status']) && $value['status'] != 'any') {
if (
($entity->isPublished() && $value['status'] == 'unpublished') ||
(!$entity->isPublished() && $value['status'] == 'published')
) {
return;
}
}
$module = 'notify_entity';
$key = 'new_post';
$to = $value['email'];
Expand Down
13 changes: 12 additions & 1 deletion src/Form/NotifyEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected function formCreateRow($entity_type, $entity_name, $bundle_type, $bund
'insert' => TRUE,
'update' => FALSE,
'delete' => FALSE,
'status' => 'any'
];

return [
'#type' => 'details',
'#title' => $title,
Expand All @@ -99,6 +99,17 @@ protected function formCreateRow($entity_type, $entity_name, $bundle_type, $bund
'#title' => $this->t('Trigger on delete'),
'#default_value' => $defaults['delete'],
],
'status' => [
'#type' => 'radios',
'#title' => $this->t('State'),
'#options' => [
'any' => $this->t('Any'),
'published' => $this->t('Published'),
'unpublished' => $this->t('Unpublished'),
],
'#access' => ($entity_type == 'node' || $entity_type == 'comment'),
'#default_value' => $defaults['status'],
],
];
}

Expand Down