I'm trying to use the soft link repository to get links for a specific version of a page, actually the latest (unpublished) version. It seems that only links relating to the published version of a page are returned, i.e.
var versionRepos = ServiceLocator.Current.GetInstance();
var versions = versionRepos.List(contentLink);
var latestContentLink = versions.Last().ContentLink;
var softLinkRepos = ServiceLocator.Current.GetInstance();
var softLinks = softLinkRepos.Load(latestContentLink, false);
The list of softLinks returned is that relating to the published version of the page, not those relating to the version defined by the latestContentLink variable. If the page has never been published then similarly it does not return any soft links for the page.
I've noticed that the CMS UI behaves in the same way, i.e. if I try to move an asset to trash, I'm not warned about any instances of content referencing that asset where the content referencing the asset is not published. Yet, if I subsequently publish that content it will successfully publish whilst referencing assets that have been deleted.
So I guess 2 queries, is this the expected behaviour or is this a bug? Is there some other method that I can use use to find all links for a page?
Some background to this, I'm hooking this into the PageData publishing event and want to cancel the publication of the page (I can do this fine with e.CancelAction and e.CancelReason), if I find assets on that page that are not yet published (I can't find these).
I logged this with EPiServer support, they have responded that this is by design because the link to unpublished content should not be returned as it would be unavailable to visitors. Interesting then, especially where this is an image, that the page can just be published with a bunch of missing (i.e. unpublished) images. Also (I'm sure this is broader than soft links) why use a parameter (content link) which is version specific and then ignore the version information in that parameter?