Select structure items in pages field

Would it be possible to select structure items in a pages field, or any other similar field, even if a plugin ?

The use-case is an artist page. She has a ‘works’ page, with ‘work-item’ subpages. Inside ‘work-item’ there is a structure field with ‘editions’.

She is asking now for a feature that would require being able to select individual editions across several works, in a single field, thus my question.

Thank you

A pages field expects pages as input. What you could do is convert the structure field items of all work-item subpages to pages and return those from a custom method.

This is assuming that the structure field contains a pages field. Could you post the blueprint definition for the editions structure field?

The structure field does not contain a pages field, but a series of other fields per instance, including a nested structure field, see:

          editionsdetail:
            label: Editions (detail)
            type: structure
            translate: false
            fields:
              produced:
                label: Produced
                type: toggle
                text:
                  - "no"
                  - "yes"
              available:
                label: Available?
                type: toggle
                text:
                  - "no"
                  - "yes"        
              location:
                type: pages
                query: kirby.page("venues").children
                multiple: false
                translate: false
              cost:
                label: Production Cost
                type: structure
                translate: false
                fields: 
                  paidby:
                    label: Paid by
                    type: pages
                    query: kirby.page("venues").children
                    multiple: false
                    translate: false   
                  paidammount: 
                    label: Ammount                  
                    type: number
                    step: 0.1
                    after: €      
                    default: 0
              price:
                label: Price
                type: number
                step: 0.1
                after: €      
                default: 0
              priceDetails:
                label: Price Details
                type: text
                default: "(+ applicable tax)"

As in the frontend we can treat structure items collections as if they were pages collections, through toStructure(), I was wondering if perhaps I could do something similar in the panel with the pages field.

Thank you

What I don’t understand: What would your user actually select here as an edition? One item in this structure field? But by what criteria, as these editions don’t seem to have a name they could be selected by?

That is a good point.

But it is possible?

If it is, I could perhaps custom build what is going to be displayed, in this case it would make sense to show ‘name of work-item’ + ‘| ed.’ + structure item index’ + ‘/’ + ‘total structure items’, something like ‘This artwork’s title | ed. 2/4’.

thanks

I’ll get back to you later tonight.

1 Like

More importantly, you will need something by which to find the selected item again. For the moment, I’m not sure if the combination of all fields in an item will be unique and will make it difficult to find the right item again. So I think some sort of unique ID would be needed. Maybe assign an AutoID via the AutoId plugin?

We could then collect all structure items of all subpages into a single collection and convert them into virtual pages in the subpages model (introduce a method virtualChildren or something like that). But as I said, these pages would require a unique slug.

Are you already on Kirby 3.8 or on a previous version?

Thanks texnixe, I’ve been discussing with the client, and I think we are going to migrate to using pages, as this solution seems overly complicated and may bring headaches in the future.

But what you propose sounds like a pretty interesting thing to try. Thanks for that. Although I’d perhaps try to use the parent unique ID + the index of the structure item on the structure items collection, as the unique id of the structure item itself. As this should be unique, shouldn’t it.

Btw, I have a few licenses bought before 3.8, can I use them in 3.8?

Thanks!

As long as the index doesn’t change, ie the items are never reordered.

Ah yes, that is true

Yes, as long as they are Kirby 3.x licenses. Kirby 3.8 doesn’t need an upgrade from any 3.x license.

1 Like