Jump to content
  • 0

talhaarif

Question

i want to loop through all these checkboxes and generate them dynamically according to their roles and to concatenate role id dynamically  with their friendly names  instead of writing them manually , is there any way to do this ? 

 

function leave_module_config()
{
    return [
        'fields' => [
            'Checkbox Field Name' => [
                'FriendlyName' => 'role1',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
                
                'FriendlyName' => 'role2',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
                
                'FriendlyName' => 'role3',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
                
                'FriendlyName' => 'role4',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
            ],
        ]
    ];
}

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

 To loop through the roles and generate the checkboxes dynamically, you can use a PHP foreach loop to iterate over an array of roles and create the checkboxes inside the loop. Here is an example of how you could do this:

function leave_module_config()
{
    $roles = ['role1', 'role2', 'role3', 'role4'];

    $fields = [
        'Checkbox Field Name' => []
    ];

    foreach ($roles as $role) {
        $fields['Checkbox Field Name'][] = [
            'FriendlyName' => $role,
            'Type' => 'yesno',
            'Description' => 'Tick to enable',
        ];
    }

    return [
        'fields' => $fields
    ];
}


This code will create a checkbox for each role in the $roles array. The FriendlyName for each checkbox will be set to the corresponding role name, and the Type and Description will be set to the same values for all checkboxes.

You can modify this code to suit your specific needs, such as by adding additional fields or by generating the role names and IDs dynamically from a database or other source.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated