Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow callable for block config options #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

damsfx
Copy link
Contributor

@damsfx damsfx commented Feb 15, 2024

Allow options for block config to be AJAX-derived options.

config:
    bg_color:
        label: Background color
        type: dropdown
        span: auto
        options: \Acme\Plugin\Classes\Helpers\ThemeHelper::staticMethodOptions

Supplying the dropdown options in the helper class :

public static function staticMethodOptions($fieldName): array
{
    return [
        'bg-red-500' => 'Red',
        'bg-blue-500' => 'Blue',
        // ...
    ];
}

or returns different options depending on the field name

public static function staticMethodOptions($fieldName): array
{
    if ($fieldName == 'bg_color') {
        return [
            'bg-red-500' => 'Red',
            'bg-blue-500' => 'Blue',
            // ...
        ];
    }
    elseif ($fieldName == 'size') {
        return [
            'w-full' => 'Full width',
            'w-2/3' => '2/3',
            'w-1/2' => '1/2',
            // ...
        ];
    }
    else {
        return ['' => '-- none --'];
    }
}

Allow options for block config to be AJAX-derived options.
@damsfx damsfx marked this pull request as draft February 16, 2024 01:58
@damsfx damsfx marked this pull request as ready for review February 16, 2024 14:06
@LukeTowers
Copy link
Member

@damsfx would you be interested in looking into refactoring the options processing in backend forms in the Winter core so that we can have a helper of some sort that can be used from anywhere in order to support all of the different ways that options can be defined (I think we're up to 6 or 7 now)?

@damsfx
Copy link
Contributor Author

damsfx commented Mar 14, 2024

@LukeTowers Yes, I'd like to ... but I need to know where to start and if it's within my reach.

@LukeTowers
Copy link
Member

@jaxwilko any pointers for @damsfx?

@jaxwilko
Copy link
Member

@LukeTowers @damsfx it's like 4am but from memory I think it happens here: https://github.com/wintercms/storm/blob/6855ef4280d2587367f6127a2bd56a89e727e490/src/Parse/Syntax/FieldParser.php#L416

Although that might just be for values defined in cms pages and not in yaml configs. @damsfx let me know how you get on and if you need help feel free to @ me :)

@bennothommo
Copy link
Member

Ideally, I think a trait that can process them would be beneficial, then we can use it wherever it is required :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants