Is there a alternative for autoID plugin?

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

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.

about moving from autoid to uuids:

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

code is based on work done by @pedroborges

site/plugins/structuuid/index.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

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

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

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?

maybe a typo in the blueprint? plase share it

here is my blueprint:

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

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?

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.

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.

Hey! Thanks a lot!!!

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

@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

1 Like