Skip to content

Commit 3ac3f8d

Browse files
committed
- (Bug Fix) Fixed an issue with the Extra Conditionals not working in the default notification type
- (API) Added new PostmasterHelper class to keep code dry that need to perform misc common functions to validate data
1 parent 2a0bfa6 commit 3ac3f8d

3 files changed

Lines changed: 47 additions & 25 deletions

File tree

core/notification_types/DefaultNotificationType.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Craft\Plugins\Postmaster\NotificationTypes;
33

4+
use Craft\PostmasterHelper;
5+
use Craft\Postmaster_TransportModel;
46
use Craft\Plugins\Postmaster\Components\BaseNotificationType;
57

68
class DefaultNotificationType extends BaseNotificationType {
@@ -9,6 +11,18 @@ class DefaultNotificationType extends BaseNotificationType {
911

1012
public $id = 'default';
1113

14+
public function onBeforeSend(Postmaster_TransportModel $model)
15+
{
16+
$this->notification->parse(array());
17+
18+
if($this->hasExtraConditionals() && !$this->areExtraConditionalsValid())
19+
{
20+
return false;
21+
}
22+
23+
return true;
24+
}
25+
1226
public function getInputHtml(Array $data = array())
1327
{
1428
return $this->craft()->templates->render('postmaster/notification_types/default/fields', $data);
@@ -23,4 +37,15 @@ public function getSettingsModelClassName()
2337
{
2438
return '\Craft\Postmaster_DefaultNotificationTypeSettingsModel';
2539
}
40+
41+
public function hasExtraConditionals()
42+
{
43+
return PostmasterHelper::hasExtraConditionals($this->getSetting('extraConditionals'));
44+
}
45+
46+
public function areExtraConditionalsValid()
47+
{
48+
return PostmasterHelper::validateExtraConditionals($this->getSetting('extraConditionals'));
49+
}
50+
2651
}

core/parcel_types/DefaultParcelType.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,12 @@ public function areTriggersValid($isNewEntry)
145145

146146
public function hasExtraConditionals()
147147
{
148-
$extra = trim($this->getSetting('extraConditionals'));
149-
150-
if($extra && !empty($extra))
151-
{
152-
return true;
153-
}
154-
155-
return false;
148+
return PostmasterHelper::hasExtraConditionals($this->getSetting('extraConditionals'));
156149
}
157150

158151
public function areExtraConditionalsValid()
159152
{
160-
return strtolower($this->settings->extraConditionals) !== 'false' ? true : false;
153+
return PostmasterHelper::validateExtraConditionals($this->getSetting('extraConditionals'));
161154
}
162155

163156
public function areStatusesValid(EntryModel $entry)
@@ -186,22 +179,6 @@ public function areSectionsValid(EntryModel $entry)
186179
return false;
187180
}
188181

189-
/*
190-
public function parseExtraConditionals(EntryModel $entry)
191-
{
192-
if($this->hasExtraConditionals())
193-
{
194-
$return = craft()->templates->renderString($this->settings->extraConditionals, array(
195-
'entry' => $entry
196-
));
197-
198-
return trim($return);
199-
}
200-
201-
return;
202-
}
203-
*/
204-
205182
public function getEvents()
206183
{
207184
if(is_array($this->settings->events) && count($this->settings->events))

helpers/PostmasterHelper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace Craft;
3+
4+
class PostmasterHelper
5+
{
6+
public static function hasExtraConditionals($extraConditionals)
7+
{
8+
if($extraConditionals && !empty($extraConditionals))
9+
{
10+
return true;
11+
}
12+
13+
return false;
14+
}
15+
16+
public static function validateExtraConditionals($extraConditionals)
17+
{
18+
return strtolower($extraConditionals) !== 'false';
19+
}
20+
}

0 commit comments

Comments
 (0)