From 4f100bc53de177e7bb00f1f471e95786dd258e78 Mon Sep 17 00:00:00 2001 From: bjorn Date: Thu, 17 Mar 2016 11:45:11 +0100 Subject: [PATCH] Added publication status as option --- notify_entity.module | 9 +++++++++ src/Form/NotifyEntityForm.php | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/notify_entity.module b/notify_entity.module index 645ee2b..3d359e3 100644 --- a/notify_entity.module +++ b/notify_entity.module @@ -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']; diff --git a/src/Form/NotifyEntityForm.php b/src/Form/NotifyEntityForm.php index 16fbca6..1d2b2af 100644 --- a/src/Form/NotifyEntityForm.php +++ b/src/Form/NotifyEntityForm.php @@ -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, @@ -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'], + ], ]; }