forked from beastbytes/yii2-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WizardMenu.php
89 lines (81 loc) · 2.33 KB
/
WizardMenu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* WizardMenu Class file
*
* @author Chris Yates
* @copyright Copyright © 2015 BeastBytes - All Rights Reserved
* @license BSD 3-Clause
* @package Wizard
*/
namespace beastbytes\wizard;
use yii\widgets\Menu;
/**
* WizardMenu class.
* Creates a menu from the wizard steps.
*/
class WizardMenu extends Menu
{
/**
* @var string The CSS class for the current step
*/
public $currentStepCssClass = 'current-step';
/**
* @var array The item to be shown to indicate completion of the wizard.
* e.g. ['label' => 'Done', 'url' => null]
*/
public $finalItem;
/**
* @var string The CSS class for future steps
*/
public $futureStepCssClass = 'future-step';
/**
* @var string The CSS class for past steps
*/
public $pastStepCssClass = 'past-step';
/**
* @var string The current step
*/
public $step;
/**
* @var \beastbytes\wizard\WizardBehavior The Wizard
*/
public $wizard;
/**
* Initialise the widget
*/
public function init()
{
$route = ['/'.$this->wizard->owner->route];
$params = $this->wizard->owner->actionParams;
$steps = $this->wizard->steps;
$index = array_search($this->step, $steps);
foreach ($steps as $step) {
$stepIndex = array_search($step, $steps);
$params[$this->wizard->queryParam] = $step;
if ($stepIndex == $index) {
$active = true;
$class = $this->currentStepCssClass;
$url = array_merge($route, $params);
} elseif ($stepIndex < $index) {
$active = false;
$class = $this->pastStepCssClass;
$url = ($this->wizard->forwardOnly
? null : array_merge($route, $params)
);
} else {
$active = false;
$class = $this->futureStepCssClass;
$url = null;
}
$this->items[] = [
'label' => $this->wizard->stepLabel($step),
'url' => $url,
'active' => $active,
'options' => compact('class')
];
if (!empty($this->finalItem)) {
$this->items[] = $this->finalItem;
}
}
}
}