|
7 | 7 | use DNADesign\SilverStripeElementalDecisionTree\Forms\DecisionTreeStepPreview; |
8 | 8 | use SilverStripe\Control\Controller; |
9 | 9 | use SilverStripe\CMS\Controllers\CMSPageEditController; |
| 10 | +use SilverStripe\Forms\LiteralField; |
10 | 11 |
|
11 | 12 | class ElementDecisionTree extends BaseElement |
12 | 13 | { |
@@ -38,18 +39,27 @@ public function getType() |
38 | 39 | public function getCMSFields() |
39 | 40 | { |
40 | 41 | $fields = parent::getCMSFields(); |
| 42 | + $fields->removeByName('FirstStepID'); |
41 | 43 |
|
42 | 44 | $introduction = $fields->dataFieldByName('Introduction'); |
43 | 45 | $introduction->setRows(4); |
44 | 46 |
|
45 | | - $fields->removeByName('FirstStepID'); |
46 | | - $stepSelector = HasOneSelectOrCreateField::create( |
47 | | - $this, 'FirstStep', 'First Step', DecisionTreeStep::get_initial_steps()->map(), $this->FirstStep(), $this |
48 | | - ); |
| 47 | + if ($this->IsInDB()) { |
| 48 | + $stepSelector = HasOneSelectOrCreateField::create( |
| 49 | + $this, 'FirstStep', 'First Step', DecisionTreeStep::get_initial_steps()->map(), $this->FirstStep(), $this |
| 50 | + ); |
| 51 | + |
| 52 | + $fields->addFieldToTab('Root.Main', $stepSelector); |
49 | 53 |
|
50 | | - $fields->addFieldToTab('Root.Main', $stepSelector); |
| 54 | + $fields->addFieldToTab('Root.Tree', DecisionTreeStepPreview::create('Tree', $this->FirstStep())); |
| 55 | + } else { |
| 56 | + $info = LiteralField::create('info', sprintf( |
| 57 | + '<p class="message info notice">%s</p>', |
| 58 | + 'Save this decision tree in order to add the first step.' |
| 59 | + )); |
51 | 60 |
|
52 | | - $fields->addFieldToTab('Root.Tree', DecisionTreeStepPreview::create('Tree', $this->FirstStep())); |
| 61 | + $fields->addFieldToTab('Root.Main', $info); |
| 62 | + } |
53 | 63 |
|
54 | 64 | return $fields; |
55 | 65 | } |
|
0 commit comments