protected function orderMedia($media)
    {
        if (null === $this->media_order) {
            /** @var Page $page */
            $page = Grav::instance()['pages']->get($this->getPath());

            if ($page && isset($page->header()->media_order)) {
                $this->media_order = array_map('trim', explode(',', $page->header()->media_order));
            }
        }

        if (!empty($this->media_order) && is_array($this->media_order)) {
            $media = Utils::sortArrayByArray($media, $this->media_order);
        } else {
            ksort($media, SORT_NATURAL | SORT_FLAG_CASE);
        }

        return $media;
    }