| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Html\FormElement; |
| 4 |
|
| 5 |
use ipl\Html\Attributes; |
| 6 |
use ipl\Html\Contract\FormSubmitElement; |
| 7 |
|
| 8 |
class SubmitButtonElement extends ButtonElement implements FormSubmitElement |
| 9 |
{ |
| 10 |
protected $defaultAttributes = ['type' => 'submit']; |
| 11 |
|
| 12 |
/** @var string The value that's transmitted once the button is pressed */ |
| 13 |
protected $submitValue = 'y'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Get the value to transmit once the button is pressed |
| 17 |
* |
| 18 |
* @return string |
| 19 |
*/ |
| 20 |
public function getSubmitValue(): string |
| 21 |
{ |
| 22 |
return $this->submitValue; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Set the value to transmit once the button is pressed |
| 27 |
* |
| 28 |
* @param string $value |
| 29 |
* |
| 30 |
* @return $this |
| 31 |
*/ |
| 32 |
public function setSubmitValue(string $value): self |
| 33 |
{ |
| 34 |
$this->submitValue = $value; |
| 35 |
|
| 36 |
return $this; |
| 37 |
} |
| 38 |
|
| 39 |
public function setLabel($label) |
| 40 |
{ |
| 41 |
return $this->setContent($label); |
| 42 |
} |
| 43 |
|
| 44 |
public function hasBeenPressed() |
| 45 |
{ |
| 46 |
return $this->getValue() === $this->getSubmitValue(); |
| 47 |
} |
| 48 |
|
| 49 |
public function isIgnored() |
| 50 |
{ |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
protected function registerAttributeCallbacks(Attributes $attributes) |
| 55 |
{ |
| 56 |
parent::registerAttributeCallbacks($attributes); |
| 57 |
|
| 58 |
$attributes->registerAttributeCallback('value', null, [$this, 'setSubmitValue']); |
| 59 |
} |
| 60 |
|
| 61 |
public function getValueAttribute() |
| 62 |
{ |
| 63 |
return $this->submitValue; |
| 64 |
} |
| 65 |
} |