Drupal\push_framework\SourceItem::determineAndSetTasks() fails to set tasks
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3365086. -->
Reported by: [alex_sansom](https://www.drupal.org/user/364473)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>I'm evaluating danse/push_framework/pf_email modules for users to be able to subscribe to content/content types.</p>
<p>Having, via /admin:</p>
<p>- configured the content type to generate the danse CRUD events<br>
- configured authenticated users to "Allow entity type subscription"/"Allow individual entity subscription"<br>
- added the subscription field to the relevant content type, and configured to be displayed to the user<br>
- enabled the pf_email module and left all settings as defaults</p>
<p>...the user can visit the relevant node and click the AJAX link and have a subscription stored in their user data.</p>
<p>If you then update the content via the node edit form and save, a DANSE event is triggered and visible in the list of all DANSE events.</p>
<p>This is all good.</p>
<p>It looks like though, when cron is next run, although there is a "Job" queued up, when it is processed, there is no email message sent for the generated event/notification.</p>
<p>Having debugged, it looks to me, with the context/configuration described above, like the first "if" condition in SourceItem::determineAndSetTasks() [1] always prevents (delivery) channels getting processed.</p>
<p>Looking further at the code history, it looks like changes [3] for this issue [2] may have affected things here.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>As per the steps laid out in the "Problem/Motivation" section</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>For me, again with the situation I described, if I change SourceItem::toArray() to return a "tasks" element value [4] of "$this->tasks ?? NULL" (instead of $this->tasks ?? []), things start working and emails get sent.</p>
<p>What I'm not sure of, being new to the module/code, is that this is the correct fix or may affect other situations (Ie when utilising the "push" functionality rather than subscription).</p>
<p>There seems to be another couple of possibilities to fix my situation:</p>
<p>Either:</p>
<p>1. SourceItem.php::determineAndSetTasks() needs to be dealing with an array and condition is: if (empty($this->tasks)) {<br>
OR, 2. SourceItem.php::determineAndSetTasks() needs to be dealing with NULL and condition is: if (!isset($this->tasks)) {<br>
OR 3. SourceItem.php::determineAndSetTasks() needs to deal with NULL and empty array if (!isset($this->tasks) || is_empty($this-tasks)) {</p>
<p>From the above, 2 is the current condition and the fix for my situation is to change [4] to 'tasks' => $this->tasks ?? NULL.</p>
<p>[1] <a href="https://git.drupalcode.org/project/push_framework/-/blob/2.2.x/src/SourceItem.php#L117">https://git.drupalcode.org/project/push_framework/-/blob/2.2.x/src/SourceItem.php#L117</a><br>
[2] <a href="https://www.drupal.org/project/push_framework/issues/3331072">https://www.drupal.org/project/push_framework/issues/3331072</a><br>
[3] <a href="https://git.drupalcode.org/project/push_framework/-/commit/8bd3c5ed55a13e7888b8d0fc39753e6d4b3fd131">https://git.drupalcode.org/project/push_framework/-/commit/8bd3c5ed55a13e7888b8d0fc39753e6d4b3fd131</a><br>
[4] <a href="https://git.drupalcode.org/project/push_framework/-/blob/2.2.x/src/SourceItem.php#L243">https://git.drupalcode.org/project/push_framework/-/blob/2.2.x/src/SourceItem.php#L243</a></p>
issue