statamic / ideas

💡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Programmatically modify blueprint sections #974

Open aerni opened 1 year ago

aerni commented 1 year ago

It would be nice if we could programmatically change blueprint sections, e.g., adding and removing fields from a section of a tab.

As of now, we can only ensure fields in a tab:

$event->blueprint->ensureFieldsInTab($fields, 'my-tab');

To make this work, sections also need a handle. I imagine something along the lines of:

$event->blueprint->ensureFieldsInSection($fields, 'my-tab', 'my-section');

Though, it might make sense to pass the config of a section instead of only its handle, so that we can also take control over the display and instructions of a section.

jasonvarga commented 1 year ago

We thought about that but it's like handle overload.

A lot of the time you just want to wrap some fields in a card without needing to label it or come up with a handle.

Maybe we can make the handle optional, and then you could do what you're describing, but of course only for sections that have been assigned handles.

tab:
  mytab:
    sections:
      -
        handle: mysection
        fields: [...]
aerni commented 1 year ago

Yeah, I understand. I think an optional handle could work. Or maybe automatically assign a handle with the index of the section and add the option to change it. This would make it easier to determine the position of certain fields when doing more complicated stuff.

tab:
  mytab:
    sections:
      -
        handle: 0
        fields: [...]
      -
        handle: 1
        fields: [...]
      -
        handle: mysection
        fields: [...]
      -
        handle: 3
        fields: [...]