/**
  * @param \Grav\Common\Page\Page|\Grav\Common\Data\Data $obj
  *
  * @return \Grav\Common\Page\Page|\Grav\Common\Data\Data
  */
 protected function storeFiles($obj)
 {
     // Process previously uploaded files for the current URI
     // and finally store them. Everything else will get discarded
     $queue = $this->admin->session()->getFlashObject('files-upload');
     $queue = $queue[base64_encode($this->grav['uri']->url())];
     if (is_array($queue)) {
         foreach ($queue as $key => $files) {
             foreach ($files as $destination => $file) {
                 if (!rename($file['tmp_name'], $destination)) {
                     throw new \RuntimeException(sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE', null), '"' . $file['tmp_name'] . '"', $destination));
                 }
                 unset($files[$destination]['tmp_name']);
             }
             if ($this->view == 'pages') {
                 $keys = explode('.', preg_replace('/^header./', '', $key));
                 $init_key = array_shift($keys);
                 if (count($keys) > 0) {
                     $new_data = isset($obj->header()->{$init_key}) ? $obj->header()->{$init_key} : [];
                     Utils::setDotNotation($new_data, implode('.', $keys), $files, true);
                 } else {
                     $new_data = $files;
                 }
                 if (isset($data['header'][$init_key])) {
                     $obj->modifyHeader($init_key, array_replace_recursive([], $data['header'][$init_key], $new_data));
                 } else {
                     $obj->modifyHeader($init_key, $new_data);
                 }
             } else {
                 // TODO: [this is JS handled] if it's single file, remove existing and use set, if it's multiple, use join
                 $obj->join($key, $files);
                 // stores
             }
         }
     }
     return $obj;
 }