Skip to content

Commit 59e51f6

Browse files
committed
Set default title for result steps
1 parent 39d3c3b commit 59e51f6

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/models/DecisionTreeStep.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class DecisionTreeStep extends DataObject
2424
'getAnswerTreeForGrid' => 'Answers'
2525
];
2626

27+
private static $default_result_title = 'Our recommendation';
28+
2729
public function getCMSFields()
2830
{
2931
$fields = parent::getCMSFields();
@@ -65,6 +67,18 @@ public function getCMSFields()
6567
return $fields;
6668
}
6769

70+
/**
71+
* Set default title on Result steps
72+
*/
73+
public function onBeforeWrite()
74+
{
75+
if ($this->Type == 'Result' && !$this->Title) {
76+
$this->Title = $this->config()->default_result_title;
77+
}
78+
79+
parent::onBeforeWrite();
80+
}
81+
6882
/**
6983
* Prevent deleting Step with answers that have dependant questions
7084
*/

templates/Includes/DecisionTreeStep.ss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<% if Step.Type == 'Question' %>
1+
<% if $Step.Type == 'Question' %>
22
<div class="step<% if $FirstStep.ID == $Step.ID %> step--first<% end_if %>">
33
<form action="$Controller.Link('getNextStepForAnswer')" method="post" class="step-form">
44
<% with $Step %>
55
<fieldset>
66
<legend class="step-legend <% if $Content %>step-legend--withcontent<% end_if %>">
7-
<span class="step-title"><span class="step-number">$PositionInPathway.</span> $Title</span>
7+
<span class="step-title">
8+
<span class="step-number">$PositionInPathway.</span>
9+
<span class="step-title-inner">$Title</span>
10+
</span>
811
<% if $Content %><span class="step-content">$Content</span><% end_if %>
912
</legend>
1013
<% if Answers %>
@@ -29,7 +32,7 @@
2932
<% else %>
3033
<div class="step step--result" aria-live="polite">
3134
<% with $Step %>
32-
<% if not $HideTitle %><div class="step-title">$Title</div><% end_if %>
35+
<% if $Title && not $HideTitle %><div class="step-title">$Title</div><% end_if %>
3336
<div class="step-content">
3437
<% if $Content %>$Content<% end_if %>
3538
<button type="button" class="step-button" data-action="restart-tree" data-target="$Top.Controller.ParentController.Link">Start again?</button>

0 commit comments

Comments
 (0)