public function mapList(array $nodes, $key, $value, $spacer) {
        $tree = [];
        $stack = [];
        $key = $key ?: $this->getRepository()->getPrimaryKey();
        $value = $value ?: $this->getRepository()->getDisplayField();
        $right = $this->getConfig('rightField');

        foreach ($nodes as $node) {
            $count = count($stack);

            while ($count && $stack[$count - 1] < $node[$right]) {
                array_pop($stack);
                $count--;
            }

            $tree[$node[$key]] = str_repeat($spacer, $count) . $node[$value];

            $stack[] = $node[$right];
        }

        return $tree;
    }