删除项目时如何模拟内容编辑器的“删除链接”选项?
我有一组项目,其中有一个树列表字段,该字段引用媒体库中的媒体项目。如果我删除由另一个项目引用的媒体项目,我会看到“损坏的链接”对话框,该对话框提供“删除链接”、“链接到另一个项目”或仅保留损坏的链接的选项。
当我选择“删除链接”时,正在调用什么 API/代码?我想在代码隐藏中以编程方式执行相同的操作。
就上下文而言,我们允许广告会员上传图像并操作他们的图像库(通过自定义网络界面)。因此,当有人从他们的集合中删除图像时,显然我们不想留下这些媒体库项目的损坏链接。
I have a set of items which have a Treelist field that references media items in the Media Library. If I delete a media item which is referenced by another item, I get the "Broken Links" dialog box which gives me the option to Remove Links, Link to Another Item, or just leave the broken links.
What API/code is being called when I select Remove Links? I would like to perform this same action programmatically in the code-behind.
For context, we are allowing our advertising members to upload images and manipulate their library of images (through a custom web interface). So when someone deletes an image from their set, obviously we don't want to leave broken links to these Media Library items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是链接数据库。您可以在删除项目之前使用它来查找引用者:
返回的 ItemLink 对象包含引用您要删除的项目的项目和字段。使用适当的 Field 类来删除引用。
尽管您可能认为 LinkDatabase 上的
RemoveLinks
或RemoveReferences
方法可以满足您的要求,但它实际上只是从链接数据库本身中删除链接/引用。编辑:
一点反射器工作就可以得到更完整的解决方案...如果您使用
FieldTypeManager
工厂来获取字段的CustomField
,您可以调用RemoveLink(ItemLink)< /code> 在球场上。
这是未经测试的代码,通过引用
Sitecore.Shell.Applications.Links.EditLinksForm
找到That would be the Link Database. You can utilize it before you delete the item to find referrers:
The returned ItemLink objects contain the item and field where the item you are deleting is referenced. Use the appropriate Field class to remove the reference.
Though you may think the
RemoveLinks
orRemoveReferences
method on the LinkDatabase will do what you're looking for, it's actually just removing links/references from the Link Database itself.EDIT:
A little Reflector work comes to a more complete solution... if you use the
FieldTypeManager
factory to get the field'sCustomField
, you can callRemoveLink(ItemLink)
on the field.This is untested code, found by referencing
Sitecore.Shell.Applications.Links.EditLinksForm