unclecheese / KickAssets

The KickAssets module for SilverStripe is an alternative to AssetAdmin
http://www.leftandmain.com
40 stars 8 forks source link

setDefaultFolder creates wrong folder #19

Open Zauberfisch opened 13 years ago

Zauberfisch commented 13 years ago

$file->setDefaultFolder('test');

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

jonom commented 13 years ago

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.

micahsheets commented 12 years ago

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}";
}