Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting root publication of component

Let’s assume the following publications for this question.

20 Content -> tcm:0-20-1

70 Web -> tcm:0-121-1

I’ve a component created under (20 Content) publication and I’m publishing this component from one of the child publications (70 Web). I’m using Dreamweaver template to write UI and I'm calling C# custom functions from DWT. While publishing, this component will be referred as 121-432 in component presentation. Is there any way to get the root publication of where the component is created? That’s I should get 20-432, instead of getting 121-432.

I’ve tried Component.GetBluePrintChain() and it returns a list that has all the blueprint hierarchy. I could get 1st item from this list to get this component with the publication where it is actually created.

Since I’ll have to call this method in many places, I just wanted to check if there any other direct/better way to get this done.

Can anyone suggest?

like image 765
Balaji Avatar asked Oct 29 '12 23:10

Balaji


1 Answers

You'll want to look at the OwningRepository property of the Component, so:

var componentIdInOwningPublication = new TcmUri(
    component.Id.ItemId,
    ItemType.Component,
    component.OwningRepository.Id.ItemId
);

Put that into a custom Dreamweaver-callable function and you should be good to go.

Update There also is a helper method called CreateTcmUriForPublication that does the translation. So you could also invoke that one like this:

var componentIdInOwningPublication = TemplateUtilities.CreateTcmUriForPublication(
    component.OwningRepository.Id.ItemId,
    component.Id
);

The end result of both snippets is the same though: the TcmUri of the Component in the context of its owning repository.

like image 164
Frank van Puffelen Avatar answered Oct 11 '22 03:10

Frank van Puffelen