I needed to generate a serial on a changing Workflow state. Most logical seemed to add a new rules action 'Generate a unique sequential number' as this provides a universal solution that can be triggered by whatever event with whatever conditions thinkable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lolandese’s picture

Status: Active » Needs work
FileSize
2.16 KB
2.81 KB

The attached patch adds the rules action 'Generate a unique sequential number'. Limitations (@TODO):

  • It kicks in if the Rules module is enabled on all serial fields of all content types. Maybe better to also add a checkbox on the field settings that confirms that behaviour over the default of generating a serial on new node save.
  • The field machine name is hardcoded manually in serial.rules.inc. So, for now change that as needed for your use case (see code comments). It should of course be grabbed dynamically.
  • It is intended to be used with the action: 'After updating existing content'. Ideally it should be extended to the event 'After saving new content', so even the normal behaviour can be replicated.

As a working example to be used with the patch a Feature module is attached that:

  • adds the serial field to a Basic page
  • generates the serial on publishing of an existing node, satisfying also an existing feature request: #1872904: Sequential Serial Numbers only for published nodes
  • once the serial exists, it won't change again, even unpublishing and republishing the node. This is general behaviour (not specific for this Feature).

Feel free to adapt it for an other use case or develop it further to commit.

Thanks.

lolandese’s picture

Issue summary: View changes
srinivasa.r’s picture

Hi, I am trying to use you patch but I am getting the following error. Could you please advise on this?

patch < serial_rules_support-2305067-1.patch
patching file serial.module
Hunk #1 FAILED at 80.
1 out of 1 hunk FAILED -- saving rejects to file serial.module.rej
patching file serial.rules.inc

Thanks in advance.

Regards,
--

Srinivas R

lolandese’s picture

FileSize
1.72 KB

Re-roll against latest dev.

delacosta456’s picture

hi lolandese
Thanks for you nice idea and work..

At the time of writing i am on Panopoly distribution 1.43 + Drupal 1.54+Rules 7.x-2.x-dev(2017-Apr-20)+Serial Field 7.x-1.8Full release 2016-Aug-31

After apply the Patch, which apply correctly, On a manual node creating process, after saving the node, serial number did not generate .. when i revert the patch it started generating correctly..

When i was writing this issue i just realize that this patch is looks to be related to dev version of Serial Field... which is the one i applied the patch to ... Could this be the reason why i am getting this issue ? is there any other possible reason?

Thnaks

lolandese’s picture

@delacosta456: It's 3 years ago I used this patch but if I recall well a rule should be defined that indicates on what action to create a serial number. I guess that you do not have a rule defined that kicks in.

It is intended to be used with the action: 'After updating existing content'. Ideally it should be extended to the event 'After saving new content', so even the normal behaviour can be replicated (see comment #1).

delacosta456’s picture

hi lolandese

Many thanks for your clarification