hi,
here is a Patch for simplenews that I think would be usefull,

Introduction
----------------
Somethimes Nodes are not created by the user via a form on the Homepage. Sometimes other modules create nodes. This could be because many nodes must be created (import) or creation of nodes is a direct result of the creation of an other node (Image) or it is not created via the Homepage (IM, Mail).
In most of this cases you want the news be send out via e-mail irregarding the path of creation.
This patch should improve simplenews so it can non-form-creation of simplenews nodes.

problem
-----------
When another module creates a simplenews node without this patch the node is created correctly but the values in the database-table are not set. This results in strange behavior. One example is that the default int value of the table is 0. When you create a new the news will get the status of 0 which means it will not be send out. This happens even if the default is to send out newsletters emedeatly.

sollution
----------
This patch checks the values of the simplenews form prior to saving it in the DB.
When the node was created from an other module without using a form the form is empty.
In this case the default values are inserted before the node is saved.

maybe you could think about merging this patch into HEAD.

thanks
angel

Comments

sutharsan’s picture

Category: support » feature
Status: Needs review » Needs work

Nice idea. Code wize you should make a default array and use array_merge() to combine it with $node->simplenews.

1st-angel’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB

hi,

i reworked the patch.

sutharsan’s picture

Status: Needs review » Needs work

The default array should contain the same values as '#default_value' in simplenews_form_alter(). From reading the patch I believe $defaults['s_format'] has a wrong value. Have you tested the patch?

'validate' is not the right place to alter the content of $node. Try 'presave'.

1st-angel’s picture

Status: Needs work » Needs review
StatusFileSize
new1.37 KB

hi,
i copied the defaults from an old patch.
now I reworked the patch. moved it to presave and tested it.

greetings

sutharsan’s picture

StatusFileSize
new1.6 KB

When you write code you should test the code thoroughly. If you would have taken a look at the node->simplenews array you would have spotted a big difference between a node submitted from a form and created by an other module. Or have you used a very old version of simplenews?
I have reworked the patch, new version attached. Please test.

sutharsan’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
simon georges’s picture

This patch seems to have been committed. Any reason this issue is still open ?

miro_dietiker’s picture

Status: Needs review » Fixed

Right, this was fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.