Move Metadata Field in SilverStripe CMS?
I am trying to move the default metadata field in SilverStripe CMS, but I cannot do it successfully. This is what I tried:
$fields->removeFieldFromTab("Root.Content.Main", "Metadata");
$fields->insertBefore(new FormField('Metadata', 'Metadata'), 'Content');
But that won't work. I can remove that field, but adding it back to where I want it is a challenge as it is not just a normal textbox or HTML field. With the above code, I get a new metadata field inserted where I want, but it is not the correct field type and does not contain any existing metadata field elements.
Is there a way to move around such a field?
+3
source to share
1 answer
We can use $fields->fieldByName('Root.Main.Metadata')
to retrieve the current metadata field so we can get it back.
Try the following:
function getCMSFields() {
$fields = parent::getCMSFields();
if ($metadataField = $fields->fieldByName('Root.Main.Metadata')) {
$fields->removeFieldFromTab('Root.Main', 'Metadata');
$fields->addFieldToTab('Root.Main', $metadataField, 'Content');
}
return $fields;
}
+3
source to share