在新Plone页面的添加页面上,我想通过将其添加到标题表单字段中来建议从文件夹标题派生的用户的标题。 在我的Plone实例中实现该行为的最佳实践是什么?
答案 0 :(得分: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);
答案 1 :(得分:1)
答案 2 :(得分:0)
您可以对Basic metadata
行为进行monkeypatch或子类化以修改_get_title的行为:https://github.com/plone/plone.app.dexterity/blob/master/plone/app/dexterity/behaviors/metadata.py#L350-L351