Commit c33e5dfd authored by TravisCarden's avatar TravisCarden

Issue #3077054 by Erik Frèrejean: Make callback arguments available while building a checklist

parent a24fd185
......@@ -28,6 +28,8 @@
* callback_checklistapi_checklist_items(). (This value is technically
* optional in order to provide backward compatibility for modules using the
* deprecated method of defining checklist items right in this array.)
* - #callback_arguments: (optional) An array of values to pass as arguments
* to the callback.
* - #description: (optional) A brief description of the checklist for its
* corresponding menu item.
* - #help: (optional) User help to be displayed in the "System help" block
......@@ -54,6 +56,7 @@ function hook_checklistapi_checklist_info() {
'#title' => t('Example checklist'),
'#path' => 'example-checklist',
'#callback' => 'callback_checklistapi_checklist_items',
'#callback_arguments' => ['Example value'],
'#description' => t('An example checklist.'),
'#help' => t('<p>This is an example checklist.</p>'),
];
......@@ -65,6 +68,10 @@ function hook_checklistapi_checklist_info() {
*
* Declared in hook_checklistapi_checklist_info().
*
* @param mixed $argument
* Any number of arguments may be passed from a checklist definition via its
* #callback_arguments array.
*
* @return array
* An array of arrays representing groups of items, to be presented as
* vertical tabs. Each group is keyed by an arbitrary identifier, unique in
......@@ -101,7 +108,7 @@ function hook_checklistapi_checklist_info() {
* @see hook_checklistapi_checklist_info()
* @see checklistapiexample_checklistapi_checklist_items()
*/
function callback_checklistapi_checklist_items() {
function callback_checklistapi_checklist_items($argument) {
return [
'example_group' => [
'#title' => t('Example group'),
......
......@@ -72,7 +72,7 @@ function checklistapi_add_checklist_items(array $definition) {
unset($definition[$child]);
}
// Invoke the callback function.
$definition += call_user_func($definition['#callback']);
$definition += call_user_func_array($definition['#callback'], $definition['#callback_arguments'] ?? []);
}
return $definition;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment