Created
April 3, 2019 01:51
-
-
Save ninty9notout/8fe0955a709795c5775a4b1abc7912f8 to your computer and use it in GitHub Desktop.
SilverStripe subsite tree drop down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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