Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Matosoft\Utils\Forms;
- use Nette\Application\Responses\TextResponse;
- use Nette\Application\UI\ISignalReceiver;
- use Nette\Application\UI\Presenter;
- use Nette\Forms\Controls\TextArea;
- use Nette\Forms\Form;
- class TexylaInput extends TextArea implements ISignalReceiver
- {
- /**
- * @var \Texy
- */
- private $texy;
- /**
- * @var Presenter
- */
- private $presenter;
- public function __construct($label = NULL, $cols = NULL, $rows = NULL)
- {
- parent::__construct($label, $cols, $rows);
- $this->monitor('Nette\Application\UI\Presenter');
- }
- protected function getPresenter()
- {
- return $this->lookup('Nette\Application\UI\Presenter');
- }
- protected function getUniqueId()
- {
- return $this->lookupPath('Nette\Application\UI\Presenter');
- }
- protected function attached($parent)
- {
- if ($parent instanceof Presenter) {
- $name = $this->getUniqueId();
- $this->setAttribute('data-previewLink', $parent->link('this', array('do' => $name . '-preview')));
- }
- parent::attached($object);
- }
- /**
- * @param string
- * @return void
- */
- public function signalReceived($signal)
- {
- if ($signal === 'preview') {
- $this->getPresenter()->sendResponse(new TextResponse($this->getTexy()->process($this->value)));
- }
- throw new \Nette\Application\UI\BadSignalException;
- }
- /**
- * @return \Texy
- */
- private function getTexy()
- {
- if ($this->texy === NULL) {
- $this->texy = new \Texy();
- }
- return $this->texy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment