PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Factory/Notification/NotificationFactory.php +54 -3 1.1 → 1.5 View file →
@@ -14,8 +14,27 @@
14 14 */
15 15 class NotificationFactory
16 16 {
17 17 /**
18 + * Lite-owned keys; everything else is treated as extension data (Pro / add-ons).
19 + *
20 + * @var string[]
21 + */
22 + private const KNOWN_NOTIFICATION_DATA_KEYS = [
23 + 'id',
24 + 'name',
25 + 'sender',
26 + 'replyTo',
27 + 'receiver',
28 + 'enabled',
29 + 'subject',
30 + 'message',
31 + 'showEmptyFields',
32 + 'smartLogic',
33 + 'formId',
34 + ];
35 +
36 + /**
18 37 * Create a NotificationEntity from an array of data.
19 38 *
20 39 * @param array<string, mixed> $data
21 40 *
@@ -23,14 +42,25 @@
23 42 * @throws InvalidArgumentException
24 43 */
25 44 public static function create(array $data): NotificationEntity
26 45 {
46 + /**
47 + * Normalize/augment notification factory input (e.g. Pro attachment fields from DB).
48 + *
49 + * @since 1.2.0
50 + *
51 + * @param array<string, mixed> $data
52 + */
53 + $data = apply_filters('ivyforms/notification/factory_data', $data);
54 +
27 55 $smartLogic = self::normalizeSmartLogic($data['smartLogic'] ?? false);
28 56
29 57 $contact = new NotificationContact(
30 58 $data['sender'] ?? '',
31 59 $data['receiver'] ?? '',
32 - $data['replyTo'] ?? ''
60 + $data['replyTo'] ?? '',
61 + $data['cc'] ?? '',
62 + $data['bcc'] ?? ''
33 63 );
34 64
35 65 $notificationValueObject = new Notification(
36 66 $data['id'] ?? 0,
@@ -38,9 +68,9 @@
38 68 $contact,
39 69 $data['enabled'] ?? true,
40 70 $data['subject'] ?? '',
41 71 $data['message'] ?? '',
42 - $data['showEmptyFields'] ?? false,
72 + (bool) ($data['showEmptyFields'] ?? false),
43 73 $smartLogic,
44 74 $data['formId'] ?? 0
45 75 );
46 76
@@ -65,8 +95,16 @@
65 95 if (isset($data['receiver'])) {
66 96 $notificationEntity->getNotificationContact()->setReceiver($data['receiver']);
67 97 }
68 98
99 + if (isset($data['cc'])) {
100 + $notificationEntity->getNotificationContact()->setCc($data['cc']);
101 + }
102 +
103 + if (isset($data['bcc'])) {
104 + $notificationEntity->getNotificationContact()->setBcc($data['bcc']);
105 + }
106 +
69 107 if (isset($data['enabled'])) {
70 108 $notificationEntity->setEnabled($data['enabled']);
71 109 }
72 110
@@ -78,9 +116,9 @@
78 116 $notificationEntity->setMessage(wp_unslash($data['message']));
79 117 }
80 118
81 119 if (isset($data['showEmptyFields'])) {
82 - $notificationEntity->setShowEmptyFields($data['showEmptyFields']);
120 + $notificationEntity->setShowEmptyFields((bool) $data['showEmptyFields']);
83 121 }
84 122
85 123 if (isset($data['smartLogic'])) {
86 124 $notificationEntity->setSmartLogic($smartLogic);
@@ -89,9 +127,22 @@
89 127 if (isset($data['formId'])) {
90 128 $notificationEntity->setFormId($data['formId']);
91 129 }
92 130
131 + $notificationEntity->setExtensionData(self::extractExtensionData($data));
132 +
93 133 return $notificationEntity;
134 + }
135 +
136 + /**
137 + * Keys in $data that are not owned by Lite.
138 + *
139 + * @param array<string, mixed> $data
140 + * @return array<string, mixed>
141 + */
142 + private static function extractExtensionData(array $data): array
143 + {
144 + return array_diff_key($data, array_flip(self::KNOWN_NOTIFICATION_DATA_KEYS));
94 145 }
95 146
96 147 /**
97 148 * Normalize smartLogic from DB/API payload.