Skip to content

Instantly share code, notes, and snippets.

@ninty9notout
Created April 3, 2019 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninty9notout/8fe0955a709795c5775a4b1abc7912f8 to your computer and use it in GitHub Desktop.
Save ninty9notout/8fe0955a709795c5775a4b1abc7912f8 to your computer and use it in GitHub Desktop.
SilverStripe subsite tree drop down
<?php
$subsites = DataObject::get(Subsite::class)->map('ID', 'Title');
$fields->insertBefore('internal_linkID',
DropdownField::create('internal_linkID_SubsiteID', 'Subsite')
->setSource($subsites->map('ID', 'Title'))
->addExtraClass('subsitestreedropdownfield-chooser no-change-track')
);
$internalLinkField = SubsitesTreeDropdownField::create(
'internal_linkID',
'Internal link',
SiteTree::class,
'ID',
'MenuTitle'
)->setDescription('If provided, overrides the external link.');
if (Controller::has_curr() && Controller::curr()->getRequest()) {
$internalLinkField->setSubsiteID(
(int) Controller::curr()->getRequest()->requestVar('internal_linkID_SubsiteID')
);
}
// In this instance, the internal_linkID already exists as a TreeDropdownField
$fields->replaceField('internal_linkID', $internalLinkField);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment