Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Include checkbox options from another file

first-time

Started by Flachy Joe 10 months ago · 9 replies · 809 views
10 months ago

Hi,

I’m Grav beginner and I’d like to give to some editors an access only to checkbox options, preventing them to change the form structure and checkboxes labels.

I currently have this form

YAML
title: 'Inscription'
published: true
visible: true
form:
    name: inscription
    fields:
        perso:
            type: section
            title: 'Personal information'
            fields:
                name:
                    label: Name
                    type: text
                    validate:
                        required: true
        choices:
            type: section
            title: 'Select at least one case'
            fields:
                firstOption:
                    label: 'Option 1'
                    type: checkboxes
                    options:
                        0802-0808: '08-02 to 08-08 2026'
                secondOption:
                    label: 'Option 2'
                    type: checkboxes
                    options:
                        0412-0418: '04-12 to 04-18 2026'
                        0419-0425: '04-19 to 04-25 2026'

Is it possible to create the date options from another file?

10 months ago

Thank for the interest.
So I have to write a PHP function which read the file and return the options?

It can't simply read the data from a yaml?

10 months ago

I find exactly what I need and very easy to use:
@Karmalakas you point me in the good direction withdata-option@ but I'm using config-options@ with a custom YAML file as described here: https://learn.getgrav.org/16/cookbook/admin-recipes

But now I have to set the permissions to allow my editor group to change only this config page 😬 Can someone help?

10 months ago

That post is about a different problem I think. Or I completely misunderstood what you're asking. Can you clarify?

10 months ago

My visitor have to choose one (or more) date by checking a box.
My editor have to enter the dates the visitor can check.
I 'd like my editor can only change this configuration, without any other access to admin.

I tried to write a plugin, it works well but the page to enter dates resides in this plugin configuration so I'd have to allow editor to access the plugin area.

I tried the stackoverflow solution linked above with a plugin to tweak the permissions of a custom configuration page but I can't get it working, nothing appear in the admin menu.

So now I'm back in the user/config/site.yaml extension by a user/blueprints/config/site.yaml file and I give the editor access to this page.

10 months ago

Oh, I've an idea: can user/blueprints/config/site.yaml crush the user/config/site.yaml with condition? So in the case the editor access it, it display only the date config but if another admin does it extends the original page.

10 months ago

@FlachyJoe, Instead of investing a lot of time and effort to prevent the user from doing anything wrong by boarding everything up, you might consider informing/educating the user about what to do, what not and its consequences.

I like the adage of the Python community: We are all adults.

10 months ago

You're obviously right but if I warn the editors about any possible misconfiguration in the admin panel then they won't log in ever and will ask me to edit for them… :face_with_bags_under_eyes:

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Japhy, 2 hours ago
0 7 2 hours ago
Forms & Blueprints · by FrViPofm, 3 weeks ago
5 274 2 weeks ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2264 8 months ago
Forms & Blueprints · by Hugo Oliveira, 9 months ago
0 728 9 months ago
Forms & Blueprints · by Augustus, 10 months ago
7 865 10 months ago