1. Go to this page and download the library: Download unclecheese/display-logic library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldsToTab("Root.Test", array(
TextField::create("Name","Name of event"),
TextField::create("VenueSize","Size of venue"),
$refreshments = CheckboxField::create("Refreshments","This is a large venue. Are there refreshments?"),
$vendors = CheckboxSetField::create("Vendors","Vendors", Member::get()->map()),
$tent = TextField::create("TentSize","You're going to need a tent. What size is it?"),
OptionSetField::create("LinkType", "", array('internal' => 'Link to an internal page', 'external' => 'Link to an external page')),
$internal = DropdownField::create("InternalLinkID", "Choose a page", SiteTree::get()->map()->toArray())->setEmptyString("-- choose --"),
$external = TextField::create("ExternalLink", "Link to external page"),
$label = TextField::create("LinkLabel", "Label for link"),
$useEmbed = CheckboxField::create("UseEmbedCode","I have embed code"),
$embed = TextareaField::create("EmbedCode","Enter the embed code.")
));
$refreshments->displayIf("VenueSize")->isGreaterThan(100);
$vendors->displayIf("Refreshments")->isChecked();
$tent->displayIf("Vendors")->hasCheckedAtLeast(3);
$internal->displayIf("LinkType")->isEqualTo("internal");
$external->displayIf("LinkType")->isEqualTo("external");
$label->displayIf("LinkType")->isEqualTo("internal")->orIf("LinkType")->isEqualTo("external");
$useEmbed->displayIf("LinkType")->isEqualTo("external");
$embed->displayIf("UseEmbedCode")->isChecked()
->orIf()
->group()
->orIf("ExternalLink")->contains("youtube.com")
->orIf("ExternalLink")->contains("vimeo.com")
->end();
return $fields;
}
use UncleCheese\DisplayLogic\Forms\Wrapper;
//...
public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldsToTab("Root.Test", array(
TextField::create("Name","Name of event"),
TextField::create("VenueSize","Size of venue"),
CheckboxField::create("Refreshments","This is a large venue. Are there refreshments?")
->displayIf("VenueSize")->isGreaterThan(100)->end(),
CheckboxSetField::create("Vendors","Vendors", Member::get()->map())
->displayIf("Refreshments")->isChecked()->end(),
TextField::create("TentSize","You're going to need a tent. What size is it?")
->displayIf("Vendors")->hasCheckedAtLeast(3)->end(),
CheckboxField::create('HasUpload', 'Has an upload'),
Wrapper::create(
UploadField::create('FileUpload', 'Upload a file'),
LiteralField::create('test', '<strong>Keep the file small!</strong>')
)->displayIf('HasUpload')->isChecked()->end(),
OptionSetField::create("LinkType", "", array('internal' => 'Link to an internal page', 'external' => 'Link to an external page')),
DropdownField::create("InternalLinkID", "Choose a page", SiteTree::get()->map()->toArray())->setEmptyString("-- choose --")
->displayIf("LinkType")->isEqualTo("internal")
->end(),
TextField::create("ExternalLink", "Link to external page")
->displayIf("LinkType")->isEqualTo("external")
->end(),
Wrapper::create(
ReadonlyField::create('URL','Base URL','http://example.com')
)->displayIf('LinkType')->isEqualTo('internal')->end(),
TextField::create("LinkLabel", "Label for link")
->displayIf("LinkType")->isChecked()->end(),
CheckboxField::create("UseEmbedCode","I have embed code")
->displayIf("LinkType")->isEqualTo("external")
->end(),
TextareaField::create("EmbedCode","Enter the embed code.")
->displayIf("UseEmbedCode")->isChecked()
->orIf()
->group()
->orIf("ExternalLink")->contains("youtube.com")
->orIf("ExternalLink")->contains("vimeo.com")
->end()
));
return $f;
}