Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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).
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff_7-10.txt | 584 bytes | colorfield |
#10 | 2847954-starting_value_init_existing-10.patch | 7.39 KB | colorfield |
#10 | serial-no-entities-init.png.png | 7.32 KB | colorfield |
#7 | serial-no-entities-to-init.png | 7.54 KB | colorfield |
#7 | serial-storage-existing-data.png | 30.08 KB | colorfield |
Comments
Comment #2
nikunjkotechaComment #3
nikunjkotechaComment #4
Truptti CreditAttribution: Truptti at Axelerant commentedVerified 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.
Comment #5
Pavan B S CreditAttribution: Pavan B S at Valuebound commentedThanks for the patch ,it is working fine
Comment #6
jo1ene CreditAttribution: jo1ene commentedThis works well. One issue though is that it does not start on the number set, but the next number.
Comment #7
colorfieldThanks 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 thatinitOldEntries()
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 offieldSettingsForm
.The patch produces this behavior:
Storage settings
Initialization confirmation
Existing entities
No existing entities
Storage settings disabled when data exists for this field
Comment #8
colorfieldComment #9
nikunjkotechaThis looks amazing, I'll give it a try.
Comment #10
colorfieldThank you @nikunjkotecha! Noticed a small typo, updated the patch (Not -> No).
Comment #11
nikunjkotechaWorks as described.
Comment #12
caspervoogt CreditAttribution: caspervoogt at Plethora commentedpatch from #10 works.
Comment #13
ShutterFreak CreditAttribution: ShutterFreak as a volunteer commentedPlease 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).
Comment #14
colorfieldThanks @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.
Comment #16
colorfield