protected function flattenChildrenArray($children, $parentTitles = [])
    {
        $output = [];

        foreach ($children as $child) {
            $childTitles = array_merge($parentTitles, [$child['title']]);
            $grandChildren = $child['children'];
            $contextString = implode('/', $parentTitles);

            $child['contextString'] = ($contextString !== '') ? $contextString . '/' : '';
            unset($child['children']);

            if (!$this->search || in_array($child['id'], $this->realSearchIds)) {
                $output[] = $child;
            }
            $output = array_merge($output, $this->flattenChildrenArray($grandChildren, $childTitles));
        }

        return $output;
    }