1 <?php
2 3 4 5 6 7
8 class FormAction extends FormField {
9
10 protected ;
11
12 protected $action;
13
14 15 16 17 18 19
20 public $useButtonTag = false;
21
22 private $buttonContent = null;
23
24 25 26
27 function setButtonContent($content) {
28 $this->buttonContent = (string) $content;
29 }
30
31
32 33 34 35 36 37 38 39 40
41 function __construct($action, $title = "", $form = null, $extraData = null, $extraClass = '') {
42 $this->extraData = $extraData;
43 $this->addExtraClass($extraClass);
44 $this->action = "action_$action";
45
46 parent::__construct($this->action, $title, null, $form);
47 }
48
49 static function create($action, $title = "", $extraData = null, $extraClass = null) {
50 return new FormAction($action, $title, null, $extraData, $extraClass);
51 }
52
53 function actionName() {
54 return substr($this->name,7);
55 }
56
57 58 59 60
61 function setFullAction($fullAction) {
62 $this->action = $fullAction;
63 }
64
65 function () {
66 return $this->extraData;
67 }
68
69 70 71 72 73 74
75 function Field() {
76 if($this->useButtonTag) {
77 $attributes = array(
78 'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''),
79 'id' => $this->id(),
80 'type' => 'submit',
81 'name' => $this->action,
82 'tabindex' => $this->getTabIndex()
83 );
84 if($this->isReadonly()) {
85 $attributes['disabled'] = 'disabled';
86 $attributes['class'] = $attributes['class'] . ' disabled';
87 }
88
89 return $this->createTag('button', $attributes, $this->buttonContent ? $this->buttonContent : $this->Title());
90 } else {
91 $attributes = array(
92 'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''),
93 'id' => $this->id(),
94 'type' => 'submit',
95 'name' => $this->action,
96 'value' => $this->Title(),
97 'tabindex' => $this->getTabIndex()
98 );
99 if($this->isReadonly()) {
100 $attributes['disabled'] = 'disabled';
101 $attributes['class'] = $attributes['class'] . ' disabled';
102 }
103 $attributes['title'] = ($this->description) ? $this->description : $this->Title();
104
105 return $this->createTag('input', $attributes);
106 }
107 }
108
109 110 111 112
113 function performReadonlyTransformation() {
114 $clone = clone $this;
115 $clone->setReadonly(true);
116 return $clone;
117 }
118
119 function readonlyField() {
120 return $this;
121 }
122 }
123
124 125 126 127
128 class FormAction_WithoutLabel extends FormAction {
129 function Title(){
130 return null;
131 }
132 }
133 ?>
134
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-