A sample custom .module file is provided in the related issue.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

miro_dietiker created an issue. See original summary.

berdir’s picture

As discussed, this has nothing to do with subscriber skipping, it happens way, way earlier.

We already have hook_simplenews_scheduler_edition_node_alter(), we could add something there that allows to skip?

miro_dietiker’s picture

Agree that there are two difference concepts of skipping. Skipping a newsletter in general, or skipping the per-user delivery.

If it is possible to configure a newsletter to consider per-recipient context to filter views or so... Then emptyness should be checked per recipient instance.
I don't know how much is possible with the site-building-only tools, what will always need code, but there is definitively demand for both.

hussainweb’s picture

I've been looking for this.

My first instinct is that if the body field is empty (or renders to empty), it should not add an edition. But I realize that simplenews passes the whole node for rendering to the theming system and there might be other fields doing the rendering. I think this is best left to custom code but simplenews_scheduler should allow for a way to support it. The obvious hook that comes to mind is hook_simplenews_scheduler_edition_node_alter.

Right now, that wouldn't work because the very next line says $edition_node->save() and there is no handler for an exception. Should we make it so that if the alter hook sets a property, e.g. simplenews_scheduler_skip_edition to TRUE, it should just exit?

hussainweb’s picture

Status: Active » Needs review
StatusFileSize
new1.36 KB

Here is a patch with the idea.

Status: Needs review » Needs work

The last submitted patch, 5: offer_skip_condition-2637482-5.patch, failed testing.

berdir’s picture

Yeah, something like that.

What if we pass that as a separate variable to the alter hook, then we can explicitly document it and it is very obvious to anyone who implements this hook how to do this if they want to?

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB

I thought it was not worth adding another parameter to the alter call, which had only one left. But then I decided that documenting it is more important. Here are the changes, with some other improvements as well. One of the things I fixed from the previous patch is that the scheduler record is update to the next run time even if the mail is not sent.

Status: Needs review » Needs work

The last submitted patch, 8: offer_skip_condition-2637482-8.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review

As I noted in another issue, the failures seem to be unrelated to the patch.

hussainweb’s picture

StatusFileSize
new3.11 KB

A tiny change in the .api.php documentation. I realize interdiff would be useful but I couldn't create it easily due to other patches. I hope the patch is not too long to review again. The only difference between #8 and this one is that this one contains &$context in .api.php.

Status: Needs review » Needs work

The last submitted patch, 11: offer_skip_condition-2637482-11.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review

Setting it back to Needs Review for unrelated failing tests.

Anonymous’s picture

Applying this patch (#11) I get the following error:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to ein_newsletters_simplenews_scheduler_edition_node_alter() must be an instance of NodeInterface, instance of Drupal\node\Entity\Node given, called in /web/core/lib/Drupal/Core/Extension/ModuleHandler.php on line 539 in ein_newsletters_simplenews_scheduler_edition_node_alter() (line 82 of modules/custom/ein_newsletters/ein_newsletters.module).

So, I understand that the patch actually changes what is being passed from Node to NodeInterface. Why is that?

Anonymous’s picture

When I change in simplenews_schedule.api.php to \Drupal\node\Entity\Node and do the same in my hook, it works. So why NodeInterface?

berdir’s picture

Your code is missing the use statement, that's not a fault of this patch. Doesn't matter if it's Node or NodeInterface, as long as it has the corresponding use or full namespace.

Anonymous’s picture

Thanks. You were right. Working now.

jocowood’s picture

StatusFileSize
new3.22 KB

I would like to suggest an addition. It would be useful to have the scheduler object in the hook, e.g. to get the interval length. Because of that I added a line of code to the patch #11 to store the scheduler object under the key 'scheduler' in the context array. My suggested patch is #12

jocowood’s picture

StatusFileSize
new2.51 KB

I updated my patch because it failed to apply

jocowood’s picture

StatusFileSize
new2.54 KB

Here is another version of the 'offer skip condition' patch because since the very first patch there was a problem with skipped editions, which nobody noticed yet. Skipped editions appear like the template under 'content' but without any additional fields changed. This is because the editions get saved on cloning. I added a 'delete' when the edition is skipped to solve this.

hussainweb’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
StatusFileSize
new5.74 KB

I rerolled the patch for 2.0.x version.

hussainweb’s picture

Ignore the patch in #21. I have forgotten how to create patches without a difftool. :D

I created a MR instead. Please review.

jaroslav červený’s picture

StatusFileSize
new2.12 KB

I created patch by #22

drupgirl’s picture

Version: 2.0.x-dev » 4.0.0-beta1

This feature is fundamental.

This patch needs a re-roll.

jocowood’s picture

StatusFileSize
new1.93 KB

I rerolled the patch for 4.0.0-beta1

Should this be a feature in the next beta version? I'll have to rebase the merge request source branch, so anybody could do a review.

jocowood’s picture

I restarted the issue fork branch based on current 4.x and applied the latest patch. The merge request is ready for a review again.

drupgirl’s picture

Is it possible to simply skip sending when the created newsletter body field is empty? This seems like it would be automatic, but evidently not.

drupgirl’s picture

jocowood’s picture

You can write your own skip condition in hook_simplenews_scheduler_edition_node_alter. Here is an example:

function your_module_simplenews_scheduler_edition_node_alter(NodeInterface $edition_node, NodeInterface $scheduler_node, array &$context) {
  if ($your_condition) {
    $context['skip_edition'] = TRUE;
  }
}
jaroslav červený’s picture

#26 patch work fine for me.