我在使用 TreeDropdownfield 的 SilverStripe 4 项目中工作。在 3.6 中,它默认获得了 MenuTitle(导航标签),但我注意到在 SilverStripe 中显示的是默认页面标题。
由于我的客户更改了页面标题,TreeDropdownField 显示长页面标题。我想显示导航标签而不是那些长页面标题,因为那些长标题的结构不清晰。
我有以下代码:
<?php
use SilverStripe\ORM\DataObject;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
class InternalLink extends DataObject {
private static $db = [
'Title' => 'Varchar',
];
private static $has_one = [
'LinkTarget' => SiteTree::class,
'InternalLinkCategory' => 'InternalLinkCategory'
];
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', TextField::create( 'Title', 'Titel link' ) );
$fields->addFieldToTab('Root.Main', TreeDropdownField::create( 'LinkTargetID', 'Doeladres', SiteTree::class ) );
return $fields;
}
}