-
-
Save hailwood/b94bf12decfea18214c510ccbbb7f87c to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Page extends Sitetree { | |
public function getCMSFields(){ | |
$this->beforeUpdateCMSFields(function (FieldList $fields) { | |
/** | |
* DECLARE FIELDS | |
*/ | |
$bannerStylesDropdown = DropdownField::create('BannerStyle', 'Style', [ | |
'None' => 'None', // /about-us/ | |
'DomainBanner' => 'Domain banner', // /domain/ | |
'SmallImage' => 'Small image', // /email/ | |
'TallImage' => 'Tall image', // /email/ | |
'SimpleCentered' => 'Simple centered', // /about-us/policies/ | |
'CallToActionBottom' => 'Bottom call to action', // /email/backup-mx/ | |
'CallToActionInline' => 'Inline call to action', // /web-hosting/ | |
'TripleActionButton' => 'Three action buttons' // /web-hosting/diy-website-builder/ | |
]); | |
$bannerTitleField = TextField::create('BannerTitle', 'Banner title'); | |
$bannerBackgroundField = UploadField::create('BannerBackgroundImage', 'Background image') | |
->setFolderName('Images/banners/backgrounds')->setAllowedFileCategories('image'); | |
$bannerButtonOneField = LinkField::create('BannerButtonOneID', 'Button one'); | |
$bannerButtonTwoField = LinkField::create('BannerButtonTwoID', 'Button two'); | |
$bannerButtonThreeField = LinkField::create('BannerButtonThreeID', 'Button three'); | |
$bannerCallToActionTextField = TextField::create('BannerCallToActionText', 'Call to action text'); | |
$bannerSubContentField = HtmlEditorField::create('BannerContent', 'Banner content')->setRows('6'); | |
/** | |
* DECLARE DISPLAY LOGIC | |
*/ | |
$bannerTitleField->displayUnless('BannerStyle')->isEqualTo('None'); | |
$bannerBackgroundField->displayUnless('BannerStyle')->isEqualTo('None') | |
->end(); | |
$bannerButtonOneField | |
->displayIf('BannerStyle')->isEqualTo('CallToActionBottom') | |
->orIf('BannerStyle')->isEqualTo('CallToActionInline') | |
->orIf('BannerStyle')->isEqualTo('TripleActionButton') | |
->orIf('BannerStyle')->isEqualTo('DomainBanner') | |
->end(); | |
$bannerButtonTwoField | |
->displayIf('BannerStyle')->isEqualTo('TripleActionButton') | |
->orIf('BannerStyle')->isEqualTo('DomainBanner') | |
->end(); | |
$bannerButtonThreeField->displayIf('BannerStyle')->isEqualTo('TripleActionButton')->end(); | |
$bannerCallToActionTextField | |
->displayIf('BannerStyle')->isEqualTo('CallToActionBottom') | |
->orIf('BannerStyle')->isEqualTo('CallToActionInline') | |
->end(); | |
$bannerSubContentField | |
->displayIf('BannerStyle')->isEqualTo('SimpleCentered') | |
->orIf('BannerStyle')->isEqualTo('CallToActionBottom') | |
->orIf('BannerStyle')->isEqualTo('CallToActionInline') | |
->orIf('BannerStyle')->isEqualTo('TripleActionButton') | |
->end(); | |
/** | |
* ADD FIELDS TO TAB | |
*/ | |
$fields->addFieldsToTab('Root.PageBanner', [ | |
$bannerStylesDropdown, | |
$bannerTitleField, | |
$bannerButtonOneField, | |
$bannerButtonTwoField, | |
$bannerButtonThreeField, | |
$bannerCallToActionTextField, | |
$bannerBackgroundField, | |
$bannerSubContentField | |
]); | |
}); | |
return parent::getCMSFields(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment