| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace SKien\Formgenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Text Area element. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @package Formgenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author Stefanius <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright MIT License - see the LICENSE file for details | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class FormTextArea extends FormInput | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** @var int col count for the textarea     */ | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     protected int $iCols; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     /** @var int rowcount for the textarea     */ | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     protected int $iRows; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * Create a textarea element. | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * @param string $strName | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * @param int $iCols | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * @param int $iRows | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * @param string $strWidth | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * @param int $wFlags | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function __construct(string $strName, int $iCols, int $iRows, string $strWidth = '95%', int $wFlags = 0)  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         parent::__construct($strName, -1, $wFlags); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->iCols = $iCols; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->iRows = $iRows; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 |  |  |         $this->addStyle('width', $strWidth); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * {@inheritDoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @see \SKien\Formgenerator\FormElement::fromXML() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $strName = self::getAttribString($oXMLElement, 'name', ''); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $iCols = self::getAttribInt($oXMLElement, 'cols', 80); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         $iRows = self::getAttribInt($oXMLElement, 'rows', 10); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $strWidth = self::getAttribString($oXMLElement, 'width', '95%'); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $wFlags = self::getAttribFlags($oXMLElement); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $oFormElement = new self($strName, $iCols, $iRows, $strWidth, $wFlags); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $oFormParent->add($oFormElement); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $oFormElement->readAdditionalXML($oXMLElement); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         return $oFormElement; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * Build the HTML-notation for the textarea | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function getHTML() : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->processFlags(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->strID = $this->strID ?: $this->strName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $strValue = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         if (!$this->oFlags->isSet(FormFlags::SET_JSON_DATA)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             $strValue = $this->oFG->getData()->getValue($this->strName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             // CR only relevant for Textareas ... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             if ($this->oFlags->isSet(FormFlags::REPLACE_BR_CR)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 $strValue = str_replace('<br>', "\n", $strValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 $strValue = str_replace('<br/>', "\n", $strValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 $strValue = str_replace('<br />', "\n", $strValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $strHTML = $this->buildContainerDiv(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $strHTML .= '<textarea'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $strHTML .= ' name="' . $this->strName . '"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $strHTML .= $this->buildClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $strHTML .= $this->buildID(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $strHTML .= ' cols="' . $this->iCols . '"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $strHTML .= ' rows="' . $this->iRows . '"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $strHTML .= $this->buildStyle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $strHTML .= $this->buildAttributes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $strHTML .= $this->buildTabindex(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $strHTML .= '>' . $strValue . '</textarea>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $strHTML .= $this->buildSelectButton('picker_top'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $strHTML .= '</div>' . PHP_EOL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |          | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  |         return $strHTML; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |  |