Pass method as parameter to class in form.md

Hello, all.

I made a plugin to solve my problem of generating fields (or form attributes) retrieving data from other pages. It works fine and it is almost generic. But, there is a but. Here is how I call my plugin within the form:

form:
    name: voting
    fields:
        -
            name: fieldset
            type: fieldset
            label: Fieldset
            data-fields@: [\Grav\Plugin\DynamicFormPlugin::mapPropertyToFormAttribute, [01.home/07._nomeados, header.categories]]

The first argument passed to DynamicFormPlugin::field is the page path. The second argument is the property that I want to use to populate my fields.

The problem: I need to pass a method (or a path to the method, I couldn’t find out how that works with grav, yaml nor php) to DynamicFormPlugin::field, so it could use that function to map the property to the form attribute.

I thought about passing class::method as a third argument to DynamicFormPlugin::field. But I don’t know how to call the method later.

I found the answer :slight_smile:

Actually, I did what I thought. Now the form.md is like this:

form:
    name: voting
    fields:
        -
            name: fieldset
            type: fieldset
            label: Fieldset
            data-fields@: [\Grav\Plugin\DynamicFormPlugin::mapPropertyToFormAttribute, [01.home/07._nomeados, header.categories]]

And I use call_user_func in DynamicFormPlugin::mapPropertyToFormAttribute to execute the function that does the mapping, passing the property to it:

/**
 * Call the function that converts the property to a form attribute,
 * passing the property as a parameter. The function needs to return the attribute info.
 */
return call_user_func($map_func_path, $selected_property);

I will publish this plugin so others can use.