I wanted to have a default starting value and I saw the TODO in the code, I have added code as part of field settings so it can be modified later easily and also can be part of field instance (and not field base).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nikunjkotecha created an issue. See original summary.

nikunjkotecha’s picture

nikunjkotecha’s picture

Status: Active » Needs review
Truptti’s picture

FileSize
48.21 KB
47.14 KB

Verified the patch 'allow_having_starting-2847954-2.patch' on Drupal 8.x-1.x, below are the observations
Before Patch :
1.The serial module does not have configuration settings to set the Starting Value
After Patch
1.The serial module have the configuration settings where user could set the Starting Value.
Attaching snapshot Before_Patch.png and After_Patch.png for reference.

Pavan B S’s picture

Assigned: Unassigned » Pavan B S
Status: Needs review » Reviewed & tested by the community

Thanks for the patch ,it is working fine

jo1ene’s picture

This works well. One issue though is that it does not start on the number set, but the next number.

colorfield’s picture

Thanks for looking into this, it is really useful and should be considered with the current behavior of initializing existing entities by default.

SerialSQLStorage::initOldEntries() is executed when the field is created. So, currently, if we have existing entities for a bundle, the behavior is that initOldEntries() is automatically executed and assigns serials from 1 to n (amount of existing entities), then we are not able to set the desired starting value anymore.

So I propose to defer the execution of initOldEntries(), with a flag that allows the site builder to also choose if the initialization must happen.

As the two settings might not change after the field creation, we should use storageSettingsForm instead of fieldSettingsForm.

The patch produces this behavior:

Storage settings
Storage settings

Initialization confirmation
Existing entities
Initialisation confirmation
No existing entities
No existing entities to init

Storage settings disabled when data exists for this field
Storage settings with existing data

colorfield’s picture

Title: Allow having starting value for the serial field. » Allow having starting value for the serial field and set existing entities initialization as optional
Status: Reviewed & tested by the community » Needs review
nikunjkotecha’s picture

This looks amazing, I'll give it a try.

colorfield’s picture

Thank you @nikunjkotecha! Noticed a small typo, updated the patch (Not -> No).

No existing entities to init

nikunjkotecha’s picture

Assigned: Pavan B S » Unassigned
Status: Needs review » Reviewed & tested by the community

Works as described.

caspervoogt’s picture

patch from #10 works.

ShutterFreak’s picture

Please note that, once you identified the correct table, you can use PHPMyAdmin to set the AUTO-INCREMENT value for the table to the next value to be used. Ideally the module would offer the option to adjust / re-number the serial sequence for existing nodes, e.g. by providing sorting mechanisms (or through Ctools and VBO).

colorfield’s picture

Thanks @ShutterFreak, with this patch it should not be necessary to alter the database manually.
Re-numbering might be another issue, feel free to create a new one for this use case.

  • colorfield committed 05ebda2 on 8.x-1.x
    Issue #2847954 by colorfield, nikunjkotecha, Truptti, Pavan B S, jo1ene...
colorfield’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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