KickAssets icon indicating copy to clipboard operation
KickAssets copied to clipboard

setDefaultFolder creates wrong folder

Open Zauberfisch opened this issue 14 years ago • 2 comments

$file->setDefaultFolder('test');

this will create 'test', and store my files in test, but it also creates a folder named 'folder'.

Zauberfisch avatar Sep 14 '11 22:09 Zauberfisch

I changed line 148 of KickAssetField.php to

$folder = $this->defaultFolder ? $this->defaultFolder : singleton('Folder');

this seems to work for me. The reason I think is that setDefaultFolder() already uses Folder::findOrMake() so a folder object was being passed as input here instead of a string.

jonom avatar Sep 26 '11 02:09 jonom

The problem seems to be caused by the BrowseLink() function.However to make it still work as intended, since $this->defaultFolder is actually a Folder Object and findOrMake needs string, the function needs to be written like this:

public function BrowseLink() {
    $folder = $this->defaultFolder
    // findOrMake requires a string for a path that is relative to the assets folder
        ? Folder::findOrMake(str_replace("assets/", "", $this->defaultFolder->Filename))
        : singleton('Folder');
    return Director::absoluteBaseURL() . "admin/files/select/{$folder->ID}";
}

micahsheets avatar Oct 27 '11 02:10 micahsheets