代码之家  ›  专栏  ›  技术社区  ›  Janmejay Kumar

在从页面的内容区域中移除块时触发事件(在内容区域中使用“移除”),当用户单击“移动到垃圾箱”时,

  •  0
  • Janmejay Kumar  · 技术社区  · 5 年前

    每当编辑器删除一个块(在内容区域中使用“删除”)并且当用户在“资源”窗格中单击一个块上的“移到垃圾箱”时,我想触发一个事件。

    我发现 datafactory.instance.movedContent 每次点击“移到垃圾桶”时触发的事件

    但当点击内容区的删除时,它并没有开火。

    更新:

    我正在执行以下步骤以实现单击“删除”

    1. 注册事件处理程序以保存页的事件和已保存的事件。

    2. 在保存事件中,获取要保存的页面,通过content area.items从内容区域获取块id。使用contentLink.id属性。

    3. 将这些id存储在一个列表中,存储在内存中的某个地方,最好是httpcontext.items集合中,因为您只需要它来处理请求,但是短时间的缓存也可以工作。现在您知道了编辑器更改之前所有块的id。

    4. 在saved事件中,获取如上所述的新id列表。现在你知道编辑器更改后的id了。某些块ID将丢失。你想做什么就做什么…

      void Instance_SavingContent(object sender, ContentEventArgs e)
      {
          if (e.Content is ListPdfDocumentBlock)
          {
              var properties = e.Content.GetType().GetProperties().Where(i => i.PropertyType == typeof(ContentArea));
              if (properties != null)
              {
                  List<int> ids = new List<int>();
                  foreach (var property in properties)
                  {
                      ContentArea contentArea = property.GetValue(e.Content) as ContentArea;
                      if (contentArea != null)
                      {
                          foreach (ContentAreaItem contentAreaItem in contentArea.Items)
                          {
                              IContent itemContent = contentAreaItem.GetContent();
                              ids.Add(itemContent.ContentLink.ID);
                          }
                      }
                  }
                  HttpContext.Current.Items.Add("pdfId", ids);
              }
          }
      }
      

    但这段代码的问题是,它总是返回更新的id。然后我将如何比较从旧到新,以确定哪个块被删除。

    1 回复  |  直到 5 年前
        1
  •  1
  •   Ted Nyberg    5 年前

    当您从内容区域中删除某个内容时,项目引用将被简单地删除 从内容区 . 从内容区域中删除的实际内容(例如块/媒体)实际上并没有被移动/删除(它仍然存在于创建位置,通常在某些资源文件夹中)。

    所以,当从内容区域中删除某个内容时,唯一发生的事情是 包含 内容区域已更改。删除的项保持不变。

    你可以把 PublishingContent 事件并将要发布的内容与当前发布的版本(如果有)进行比较,并比较其内容区域中的项,以查看是否添加或删除了任何内容。

    推荐文章