public static function prepare_listing($listing) {
        $wasobject = false;
        if (is_object($listing)) {
            $listing = (array) $listing;
            $wasobject = true;
        }

        // Prepare the breadcrumb, passed as 'path'.
        if (isset($listing['path']) && is_array($listing['path'])) {
            $listing['path'] = self::prepare_breadcrumb($listing['path']);
        }

        // Prepare the listing of objects.
        if (isset($listing['list']) && is_array($listing['list'])) {
            $listing['list'] = self::prepare_list($listing['list']);
        }

        // Convert back to an object.
        if ($wasobject) {
            $listing = (object) $listing;
        }
        return $listing;
    }