Re-order id after deleting a content in drupal 8

Viewed 56

I am new to Drupal and I came to a scenario where i have created an auto-incremented "order no" and its working correctly, but on deleting a content data, the "order no" field is not re-ordering. (client requirement)

For Example:

    • some data1
    • some data2
    • some data3

if I delete 2, the new order should be:

    • some data1
    • some data3

Any help will be much appreciated.

1 Answers

You can achieve this by write custom hook or rules module, whenever delete node hook trigger, update auto_increment value with previous one for all nodes from deleted node using node update hook as well as update last auto_increment value in specific table for next node creation. You can also do by query update in table. But you have to check carefully which are tables involved.

Related