Im using Episerver 11.12
I have designed a gadget which will allow the user to delete the content for the selected language. So when the user selects the content page in the dropdown and the language and click on delete below line of code executes in the backend and it deletes the page content for that language.
DataFactory.Instance.DeleteLanguageBranch(page.PageLink, language, AccessLevel.Delete);
But i noticed that it only deletes the page and not the block in that language which was inside that page.
So for example: If i have a page1 in language(en, de) which has block1 in language(en, de) by the help of the above code only page1 de language gets deleted and if we look inside block1 i can see both languages present.
Can anyone help me on how i can delete the content inside those pages for that language.
Blocks / Content isn't directly linked to a page, they are held seperately
You need to when going to delete a page look at the content area(s) on that page and loop through and delete the blocks as well
The only issue with this is those blocks might be used on other pages, so you could cause issues doing this
Yikes—this sounds kinda risky. How’d you know a block is not being used elsewhere?
First thing, don’t use the DataFactory: you should be using the IContentRepository and dependency injection (DataFactory is legacy).
The closest approximation of what you want to do would be to use the IContentSoftLinkRepository, a very simple (read: untested) example would be:
// Get all the soft links for the specified page
var softLinks = _contentSoftLinkRepository.Load(page.PageLink).ToList();
// Use the Content Repository to load the content, filters to only the blocks
var blocks = _contentRepository.GetItems(softLinks.Select(x => x.ReferencedContentLink), new CultureInfo(language)).OfType<BlockData>();
Note that a block could be referenced a few different ways: in a ContentArea, in a list of ContentReferences, in a rich text area or as a ContentReference. The above example wouldn't return the block if it was reference via a ContentReference property (although this is potentially unlikely) because it wouldn't be a soft link.