Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created April 16, 2016 22:17
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 hailwood/b94bf12decfea18214c510ccbbb7f87c to your computer and use it in GitHub Desktop.
Save hailwood/b94bf12decfea18214c510ccbbb7f87c to your computer and use it in GitHub Desktop.
<?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