File Selection in Page Attributes
Permalink
I've added a page attribute of the type File. So, I get to choose a file in the property editor window.
I get the selected file in my theme php script using $c->getCollectionAttributeValue('header_img').
I want to use the file (image) url in an img tag, so I just need the url, no other functionality.
I can't use the returned value directly, as it seems to be of type LibraryFileBlockController. I looked into the API and there is no documentation of such type. So, ... I thought I'd ask here before diving into the core's source code to find out the methods.
Also, I'd like to ask if there's a way to avoid the object creation overhead, since what I need from the attribute is simply only the string value of the attribute, and the only difference from a string type attribute I need is that I get to choose the file in the property editor window.
And thanks :)
I get the selected file in my theme php script using $c->getCollectionAttributeValue('header_img').
I want to use the file (image) url in an img tag, so I just need the url, no other functionality.
I can't use the returned value directly, as it seems to be of type LibraryFileBlockController. I looked into the API and there is no documentation of such type. So, ... I thought I'd ask here before diving into the core's source code to find out the methods.
Also, I'd like to ask if there's a way to avoid the object creation overhead, since what I need from the attribute is simply only the string value of the attribute, and the only difference from a string type attribute I need is that I get to choose the file in the property editor window.
And thanks :)
I was looking for the 'getFileRelativePath' name, thanks.
I looked up the documentation but there were no place that I could check the method listing of the class.
BTW, if I use this my code will break in 5.3?
I looked up the documentation but there were no place that I could check the method listing of the class.
BTW, if I use this my code will break in 5.3?
but I do know the idea is that the entire libraryfileblockcontroller will be rewritten to accommodate and forward the requests to the file and file version php files for the sake of backwards compatibility.
I am not sure if this helps, but I am going to include code I use in the current beta:
Yeah so that is essentially identical and I am using a 25+ revision old beta so you should be fine to use the controller or at least know that both are compatible :)
I am not sure if this helps, but I am going to include code I use in the current beta:
//class independent Loader::model('file_version'); Loader::model('file_set'); function getRelativePath() { $hotdog = $this->getFileObject(); $fv = $hotdog->getVersion(); return $fv->getRelativePath(); }
Yeah so that is essentially identical and I am using a 25+ revision old beta so you should be fine to use the controller or at least know that both are compatible :)
so say you are getting the file object ie something like:
$image = $c->GetCollectionAttributeValue('header');
then you could so something like
$imgurl = $image->getFileRelativePath(); and wrap that in img tags to make it render.
Even though it is changing all calls to libraryfile will just map to the file and file_version models.