-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
217 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,10 @@ | ||
<?php | ||
namespace Packaged\Form\Decorators; | ||
|
||
use Exception; | ||
use Packaged\Form\Decorators\Interfaces\Decorator; | ||
use Packaged\Glimpse\Core\HtmlTag; | ||
use Packaged\Helpers\Arrays; | ||
use Packaged\SafeHtml\SafeHtml; | ||
use Packaged\Ui\Html\HtmlElement; | ||
|
||
abstract class AbstractDecorator implements Decorator | ||
abstract class AbstractDecorator extends HtmlElement implements Decorator | ||
{ | ||
protected $_attributes = []; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId(): ?string | ||
{ | ||
return $this->getAttribute('id'); | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* | ||
* @return $this | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->addAttribute('id', $id); | ||
return $this; | ||
} | ||
|
||
public function addAttribute($name, $value) | ||
{ | ||
$this->_attributes[$name] = $value; | ||
return $this; | ||
} | ||
|
||
public function getAttribute($name): ?string | ||
{ | ||
return Arrays::value($this->_attributes, $name); | ||
} | ||
|
||
public function removeAttribute($name) | ||
{ | ||
unset($this->_attributes[$name]); | ||
return $this; | ||
} | ||
|
||
public function hasAttribute($name): bool | ||
{ | ||
return array_key_exists($name, $this->_attributes); | ||
} | ||
|
||
/** | ||
* @param HtmlTag $ele | ||
* | ||
* @return HtmlTag $ele | ||
*/ | ||
protected function _hydrateElement(HtmlTag $ele) | ||
{ | ||
return $ele->setAttributes($this->_attributes); | ||
} | ||
|
||
/** | ||
* @return HtmlTag | ||
*/ | ||
abstract protected function _getElement(); | ||
|
||
/** | ||
* @return string | ||
* @throws Exception | ||
*/ | ||
public function render(): string | ||
{ | ||
return (string)$this->produceSafeHTML(); | ||
} | ||
|
||
/** | ||
* @return SafeHtml | ||
* @throws Exception | ||
*/ | ||
public function produceSafeHTML(): SafeHtml | ||
{ | ||
return $this->_getElement()->produceSafeHTML(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
<?php | ||
namespace Packaged\Form\Decorators; | ||
|
||
use Packaged\Glimpse\Core\HtmlTag; | ||
use Packaged\Glimpse\Tags\Form\Input; | ||
use Packaged\SafeHtml\SafeHtml; | ||
use Packaged\Ui\Html\HtmlElement; | ||
|
||
class HiddenInputDecorator extends InputDecorator | ||
{ | ||
protected $_type = Input::TYPE_HIDDEN; | ||
protected $_tag = ''; | ||
|
||
public function produceSafeHTML(): SafeHtml | ||
protected function _formatElements(HtmlTag $input, ?HtmlTag $label, ?HtmlTag $errors) | ||
{ | ||
return SafeHtml::escape([$this->_getInputElement(), $this->_getErrorElement()], ''); | ||
return [$input, $errors]; | ||
} | ||
|
||
protected function _initLabelElement(): ?HtmlTag | ||
{ | ||
return null; | ||
} | ||
|
||
protected function _configureInputElement(HtmlElement $input) | ||
{ | ||
$input->setAttribute('type', Input::TYPE_HIDDEN); | ||
parent::_configureInputElement($input); | ||
} | ||
} |
Oops, something went wrong.