original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Order the media based on the page's media_order
  
  @param array $media
  @return array
docstring_tokens: Order the media based on the page s media_order