protected function getDestinationFolder()
    {
        if ($this->destinationFolder === false) {
            $replacingFile = $this->getFileToBeReplaced();
            if ($replacingFile !== null) {
                $folder = $replacingFile->getFileFolderObject();
            } else {
                $treeNodeID = $this->request->request->get('currentFolder');
                if ($treeNodeID) {
                    $treeNodeID = is_scalar($treeNodeID) ? (int) $treeNodeID : 0;
                    $folder = $treeNodeID === 0 ? null : Node::getByID($treeNodeID);
                } else {
                    $filesystem = new Filesystem();
                    $folder = $filesystem->getRootFolder();
                }
            }
            if (!$folder instanceof FileFolder) {
                throw new UserMessageException(t('Unable to find the specified folder.'));
            }
            if ($replacingFile === null) {
                $fp = new Checker($folder);
                if (!$fp->canAddFiles()) {
                    throw new UserMessageException(t('Unable to add files.'), 400);
                }
            }
            $this->destinationFolder = $folder;
        }

        return $this->destinationFolder;
    }