Commit a762bf7d authored by chr.fritsch's avatar chr.fritsch Committed by TravisCarden

Issue #2904660 by chr.fritsch: Url objects in...

Issue #2904660 by chr.fritsch: Url objects in hook_checklistapi_checklist_info() cause RuntimeException: Recursive router rebuild detected
parent a1bdb85a
......@@ -53,9 +53,31 @@ function checklistapi_checklist_access($id, $operation = 'any') {
*/
function checklistapi_checklist_load($id) {
$definition = checklistapi_get_checklist_info($id);
$definition = checklistapi_add_checklist_items($definition);
return ($definition) ? new ChecklistapiChecklist($definition) : FALSE;
}
/**
* Adds the checklist items to a given definition.
*
* @param array $definition
* A checklist definition as returned from checklistapi_get_checklist_info().
*
* @return array
* The checklist definition with checklist items added.
*/
function checklistapi_add_checklist_items(array $definition) {
if (!empty($definition['#callback']) && is_callable($definition['#callback'])) {
// Remove any checklist items from the original definition.
foreach (Element::children($definition) as $child) {
unset($definition[$child]);
}
// Invoke the callback function.
$definition += call_user_func($definition['#callback']);
}
return $definition;
}
/**
* Determines whether the current user is in compact mode.
*
......@@ -87,6 +109,9 @@ function checklistapi_get_checklist_info($id = NULL) {
if (!isset($definitions)) {
// Get definitions.
$definitions = \Drupal::moduleHandler()->invokeAll('checklistapi_checklist_info');
foreach ($definitions as $key => $value) {
$definitions[$key] = checklistapi_add_checklist_items($value);
}
$definitions = checklistapi_sort_array($definitions);
// Let other modules alter them.
\Drupal::moduleHandler()->alter('checklistapi_checklist_info', $definitions);
......
......@@ -248,6 +248,7 @@ class ChecklistapiChecklist {
// Loop through items.
foreach ($group as $item_key => $item) {
$definition = checklistapi_get_checklist_info($this->id);
$definition = checklistapi_add_checklist_items($definition);
if (!in_array($item_key, array_keys($definition[$group_key]))) {
// This item wasn't in the checklist definition. Don't include it with
// saved progress.
......
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