silverstripe-framework: Image not loading through ORM in SS4
I have a ModularPage class that extends Page. Page has a ‘Thumbnail’ Image.
I have an route for ajaxing a ‘ModularPage’ collection. I grab the collection with the following:
$rootPage = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $id);
$pages = $rootPage->Children();
foreach ($pages as $page) {
var_dump($page->Thumbnail()->Link()); // Null
var_dump($page->ThumbnailID); // '4'
}
The ThumbnailID is populated but the thumbnail object is null. Is this a bug? Do I need to do anything different in SS4?
Update: So when I access the route directly from the browser the Link populates correctly. When accessing it through Ajax, Link is null.
Update 2: The image Link() also works as per normal when accessed from the same class, only when called through ajax does it get stripped.
Update 3: I have spun this up in SS3 and the image comes back no problem.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 18 (12 by maintainers)
Note to @sminnee ; We might want to sneak in a “published” state indicator to files to help reduce this issue coming out in alpha2. I dont see either a publish state or button in the current asset admin.
Just throwing out ideas here, could it be that the file isn’t published when the page is? If you view it in the browser, you could be in stage mode (which would display the file).
Try this in your page class.
This should trigger your thumbnails to get published whenever your pages are published.
If you’re not sure, try debugging the state of your File, SiteTree, File_Live and SiteTree_Live records.
Hi @nickspiel , I’ve created https://github.com/silverstripe/silverstripe-framework/issues/6059 to follow up to this conversation. It doesn’t address every issue, but it is another step towards making versioned more natural to use.