2

在新 Plone 页面的添加页面上,我想通过将文件夹标题添加到标题表单字段中来向用户建议一个标题。在我的 Plone 实例中实现该行为的最佳实践是什么?

4

3 回答 3

3

另一种解决方案是分别使用 Javascript 和 jQuery:

(function($) { $(document).ready(function() {

  // A Dexterity-based document is added:
  if( window.location.href.endsWith('/++add++Document') ) {

    // Grab the parent's title of the current title-tag's content:
    var title = $('title')[0].innerHTML.split(' — ')[0]

    // Prefill the new document's title-field with the parent's title:
    $('#form-widgets-IDublinCore-title').val(title)
  }

  // An Archetypes-based document is added:
  if( window.location.href.indexOf('/portal_factory/Document/') > -1 ) {
    var parentUrl= document.referrer
    var parentTitleEleId = 'parent-fieldname-title'

    // Provide ele to load parent's title into:
    var loadEle = document.createElement('span')

    // Load parent's title into ele:
    $(loadEle).load(parentUrl + ' #' + parentTitleEleId, function() {

      // After loading finished, fetch parent-title of ele, remove
      // trailing spaces and set it into the new doc's title-field:
      $('#title').val(loadEle.childNodes[0].innerHTML.trim())

      // Thy had served y'er purpose, vanish:
      loadEle.remove()

    });

  }

});})(jQuery);
于 2016-08-18T10:18:14.490 回答
1

您可以在Docs中找到更多关于 MonkeyPatching 的内容。另一种解决方案是,您可以注册自己的 AddForm 并设置 Textline-Widget 的 Value。要创建自定义 AddForm,请查看Docs

于 2016-08-18T06:57:49.240 回答
0

您可以对行为进行monkeypatch或子类化Basic metadata以修改_get_title的行为:https ://github.com/plone/plone.app.dexterity/blob/master/plone/app/dexterity/behaviors/metadata.py#L350-L351

于 2016-08-17T20:36:52.517 回答