bytic /
form
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Nip\Form\Traits; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Trait MessagesTrait |
||
| 7 | * @package Nip\Form\Traits |
||
| 8 | */ |
||
| 9 | trait MessagesTrait |
||
| 10 | { |
||
| 11 | protected $_messages = [ |
||
| 12 | 'error' => [], |
||
| 13 | ]; |
||
| 14 | |||
| 15 | protected $_messageTemplates = []; |
||
| 16 | |||
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $type |
||
| 20 | * @return mixed |
||
| 21 | */ |
||
| 22 | public function getMessagesType($type = 'error') |
||
| 23 | { |
||
| 24 | return $this->_messages[$type]; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param $message |
||
| 29 | * @param string $type |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | public function addMessage($message, $type = 'error') |
||
| 33 | { |
||
| 34 | $this->_messages[$type][] = $message; |
||
| 35 | |||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function getMessages() |
||
| 43 | { |
||
| 44 | $messages = $this->_messages; |
||
| 45 | $messages['error'] = $this->getErrors(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 46 | |||
| 47 | return $messages; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $name |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | public function getMessageTemplate($name) |
||
| 55 | { |
||
| 56 | return isset($this->_messageTemplates[$name]) ? $this->_messageTemplates[$name] : null; |
||
| 57 | } |
||
| 58 | } |
||
| 59 |