# Is there a alternative for autoID plugin?

**URL:** <https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161>\
**Category:** Questions\
**Tags:** v4\
**Created:** [December 1, 2023, 12:31am UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161 "2023-12-01T00:31:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [December 1, 2023, 12:31am UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/1 "2023-12-01T00:31:24Z")

</div>

Hi,  
is there in K4 a alternative for the old autoid plugin as id field?  
I use it in a sit a lot also for dynamic js things in kirbytags. actiall I have set the old autoid filds to text. So I can use the old IDs further but not new ones. Same problem in structurefields.

Best

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 1, 2023, 7:39am UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/2 "2023-12-01T07:39:18Z")

</div>

Kirby has UUIDs for pages, files and users since 3.8. You could continue to use your old autoids if you rename the field from `autoId` to `uuid`. But no solution for structure fields so far.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [December 1, 2023, 10:38am UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/3 "2023-12-01T10:38:34Z")

</div>

about moving from autoid to uuids:

> [@Migration Autoid to Kirby UUIDs](https://forum.getkirby.com/t/migration-autoid-to-kirby-uuids/28212):
>
> If anybody wants to migrate from kirby-autoid to native UUIDs this worked quite well for me. \<?php return ['description' =\> 'Autoid\>uuid bruteforce replacer', 'args' =\> [], 'command' =\> static function ($cli): void { $index = site()-\>index(); $replacements = 0; foreach($index as $autoidPage) { if($autoidPage-\>autoid()-\>isNotEmpty()) { $autoid = $autoidPage-\>autoid()-\>value(); foreach($index-\>not($autoidPage) as …

and there is a thread in discord on how to create custom uuid for structures. BUT no solution for duplicating entries!

> **[Discord - A New Way to Chat with Friends & Communities](https://discord.com/channels/525634039965679616/1088408228452384852)**
>
> Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

code is based on work done by @pedroborges

**site/plugins/structuuid/index.php**

```php
<?php

use Kirby\Cms\App as Kirby;

/*
 myStructure:
    type: structure
    fields:
      uniqueId:
        type: structure-uuid
 */

Kirby::plugin('bnomei/unique-ids-for-structures', [
    'fields' => [
        'structure-uuid' => [
            'computed' => [
                'value' => function () {
                    return $this->value ?? uuid();
                },
            ],
        ],
    ],
]);

```

**site/plugins/structuuid/index.js**

```js
panel.plugin('bnomei/unique-ids-for-structures', {
  fields: {
    'structure-uuid': {
      template: '<template></template>',
      mounted() {
this.$el.parentElement.parentElement.remove()
      },
    }
  }
});

```

---

<div class="post-metadata">

**Author:** ![matzebuchholz](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matzebuchholz](https://forum.getkirby.com/u/matzebuchholz)\
**Post date:** [January 15, 2024, 8:56am UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/4 "2024-01-15T08:56:41Z")

</div>

Thanks a lot for this Code, but unfortunately I can not handle this. ☹

The code is generating uuids for the structure items, but

1. the uuid changes with every page-refresh and
2. all other fields of the structure item are hidden and the structure item view is totally blank.

Am I too stupid?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 15, 2024, 12:37pm UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/5 "2024-01-15T12:37:35Z")

</div>

maybe a typo in the blueprint? plase share it

---

<div class="post-metadata">

**Author:** ![matzebuchholz](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matzebuchholz](https://forum.getkirby.com/u/matzebuchholz)\
**Post date:** [January 15, 2024, 12:56pm UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/6 "2024-01-15T12:56:34Z")

</div>

here is my blueprint:

```auto
title: Seite Gigs

num: 0

tabs:
  gigs:
    label: Gigs
    icon: calendar
    columns:
      - width: 1/1
        sections:
          gigssection:
            type: fields
            fields:
              gigsdata:
                label: Gigs
                type: structure
                translate: false
                sortBy: datum asc
                columns:
                  datum:
                    width: 2/12
                  uhrzeit:
                    width: 1/12
                  artist:
                    width: 5/12
                  location:
                    width: 4/12
                fields:
                  datum:
                    label: Datum
                    type: date
                    default: now
                    required: true
                    width: 1/2
                  uhrzeit:
                    label: Uhrzeit
                    type: time
                    default: now
                    width: 1/2
                  artist:
                    label: Künstler
                    type: select
                    required: true
                    options: query
                    query:
                      fetch: page.artistsdata.toStructure
                      text: "{{ structureItem.artistname }}"
                      value: "{{ structureItem.autoid }}"
                  location:
                    label: Location
                    type: select
                    required: true
                    options: query
                    query:
                      fetch: page.locationsdata.toStructure
                      text: "{{ structureItem.locationname }} in {{ structureItem.stadt }}"
                      value: "{{ structureItem.autoid }}"
                  va_name:
                    label: Titel der Veranstaltung
                    type: text
                  ticketlink:
                    label: Ticket-URL
                    type: url
      - width: 1/4
        sections:
          sectionright:
            type: fields
            fields:
              bg_image:
                label: Header-Foto
                type: files
                multiple: false
                layout: cards
                min: 0
                max: 1
                info: "{{ file.dimensions }}"
                empty:
                help: "Sinnvoll sind Fotos im Querformat. Der relevante Bereich des Bildes sollte mittig sein."
      - width: 1/4
        sections:
          fotos:
            headline: Zu dieser Seite hochgeladene Dateien
            type: files
  artists:
    label: Künstler
    icon: users
    fields:
      artistsdata:
        label: Künstler
        type: structure
        translate: false
        fields:
          autoid:
            type: hidden
          uniqueId:
            type: structure-uuid
          artistname:
            label: Name des Künstlers
            type: text
            required: true
          artisturl:
            label: Künstler-URL
            type: url
  locations:
    label: Locations
    icon: map
    fields:
      locationsdata:
        label: Locations
        type: structure
        translate: false
        fields:
          autoid:
            type: text
          uniqueId:
            type: structure-uuid
          locationname:
            label: Name der Location
            type: text
            required: true
          locationurl:
            label: Location-URL
            type: url
          stadt:
            label: Stadt
            type: text
            required: true

```

---

<div class="post-metadata">

**Author:** ![matzebuchholz](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matzebuchholz](https://forum.getkirby.com/u/matzebuchholz)\
**Post date:** [January 16, 2024, 9:53am UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/7 "2024-01-16T09:53:05Z")

</div>

what I don’t understand (I am really NOT good building custom plugins) is that the uuid isn’t saved in the content file. perhaps I misunderstand the plugin code?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 16, 2024, 12:48pm UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/8 "2024-01-16T12:48:58Z")

</div>

> [@bnomei](#):
>
> `$this->value ?? uuid();`

it should generate one if there is none and save that to the file and then keep that one. i will validate with a k4 setup as soon as possible.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 16, 2024, 1:07pm UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/9 "2024-01-16T13:07:39Z")

</div>

> [@bnomei](#):
>
> `this.$el.parentElement.parentElement.remove()`

k4 needs an adjustment  
`this.$el.parentElement.parentElement.remove()`  
should be  
`this.$el.parentElement.remove()`

also you need to save AND reload the panel (via browser) once after you added entries before editing again. the simple code can not detect that a value has already been written.

so when you add a new value until you do the refresh the panel thinks there has been no uuid and will create a new one on every save BUT once written and refreshed they will persist.

for your usual workflow… just create all entries in a structure and save. navigate to another page and use the uuid there. that should be fine.

---

<div class="post-metadata">

**Author:** ![matzebuchholz](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@matzebuchholz](https://forum.getkirby.com/u/matzebuchholz)\
**Post date:** [January 16, 2024, 2:36pm UTC](https://forum.getkirby.com/t/is-there-a-alternative-for-autoid-plugin/30161/10 "2024-01-16T14:36:10Z")

</div>

Hey! Thanks a lot!!!

this adjustment made the change! It’s working fine!

[@kirby-team](https://forum.getkirby.com/groups/kirby-team): is it right, that you are working on a solution to bring this feature in the core? And if yes: for which version is it planned?

@bnomei: if it’s not going into the core, it would be really great if you would this code an official plugin, perhaps with the duplicate-thing fixed…

I really often need this feature and for now you helped me so much! Big thanks to you
