Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

IncrementingGenerator value on structure field starts at 2 #74

Open
pReya opened this issue Jan 16, 2022 · 3 comments
Open

IncrementingGenerator value on structure field starts at 2 #74

pReya opened this issue Jan 16, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@pReya
Copy link
Contributor

pReya commented Jan 16, 2022

This is a minor bug, but it's annoying because the AutoIDs don't match the default row enumerations in the Kirby panel for structure fields.

To reproduce:

  1. Install plugin and set it to use IncrementingGenerator
  2. Add a field of type: autoid to an existing structure field
  3. Add or edit existing field, so AutoIDs get generated
  4. Resulting IDs start with value 2 (should be 1)
@pReya pReya changed the title IncrementingGenerator on structure field starts at 2 IncrementingGenerator value on structure field starts at 2 Jan 16, 2022
@bnomei bnomei self-assigned this Jan 25, 2022
@bnomei bnomei added the bug Something isn't working label Jan 25, 2022
@bnomei
Copy link
Owner

bnomei commented Jan 27, 2022

how exactly did you setup the generator? the seed is expected by default to start with 0. the created .autoid file will store the most recent used id.

are there any other autoid fields that might get set (to the value 1) before the structure is parsed?

@pReya
Copy link
Contributor Author

pReya commented Jan 29, 2022

I tried this again, to make sure this is not due to another plugin or my complicated blueprints, but I can recreate it, even with a plainkit setup. So I'm pretty sure this is actually a bug. How to reproduce:

  1. Set up new plainkit project
  2. Add a new structure field to blueprint, e.g. default.yml
    title: Default Page
    preset: page
    fields:
      text:
        label: Text
        type: textarea
        size: large
      mydata:
        label: Addresses
        type: structure
        translate: false
        fields:
          firstname:
            label: First Name
            type: text
          lastname:
            label: Last Name
            type: text
  3. Add new entry to structure via the panel, so content file looks something like this:
    Title: Test
    
    ----
    
    Text: asd
    
    ----
    
    Mydata:
    
    - 
      firstname: Michael
      lastname: Meyers
    
  4. Install the plugin
  5. Add to config.php
    'bnomei.autoid.generator' => function () {
            return (new \Bnomei\IncrementingGenerator(0))->generate();
        },
    
  6. Add autoid field to blueprint:
    title: Default Page
    preset: page
    fields:
      text:
        label: Text
        type: textarea
        size: large
      mydata:
        label: Addresses
        type: structure
        translate: false
        fields:
          autoid:
            type: hidden
            translate: false
          firstname:
            label: First Name
            type: text
          lastname:
            label: Last Name
            type: text
    
  7. Add new item to structure, save page
  8. Autoid in content file starts with "2"
      Title: Test
      
      ----
      
      Text: asd
      
      ----
      
      Mydata:
      
      - 
        autoid: "2"
        firstname: Michael
        lastname: Meyers
      - 
        autoid: "3"
        firstname: Peter
        lastname: Mueller
    

@janstieler
Copy link

I used the Autoid on otherpages with the regular generator but on the homepage I use the increment generator and it starts by 14. I have no clue if the generator switch is a problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants