Issue Bug Closed

#88118Loose reference while remove items from a tree based on a callback in PageTreeRepository

Steve Lenz 04/09/19, 10:54 updated 06/06/24, 09:59

Description

Hook “$GLOBALS[‘TYPO3_CONF_VARS’][‘SC_OPTIONS’][‘t3lib/class.t3lib_userauthgroup.php’][‘calcPerms’]” in BackendUserAuthentication has no effect.

The bug is in PageTreeRepository::applyCallbackToChildren in line 145:

/**
     * Removes items from a tree based on a callback, usually used for permission checks
     *
     * @param array $tree
     * @param callable $callback
     */
    protected function applyCallbackToChildren(array &$tree, callable $callback)
    {
        if (!isset($tree['_children'])) {
            return;
        }
        foreach ($tree['_children'] as $k => $childPage) {
            if (!call_user_func_array($callback, [$childPage])) {
                unset($tree['_children'][$k]);
                continue;
            }
            $this->applyCallbackToChildren($childPage, $callback);
        }
    }

The unset does not effect on _children array, because the iteration ignores the reference.

The solution to set reference for $childPage:

foreach ($tree['_children'] as $k => &$childPage) {
...
}

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.