* @copyright Tamaranga */ class StaticText extends Input { const NONAME_PREFIX = '__static'; /** @var string|callable содержимое или функция его формирующая */ protected $content = ''; /** @var null|bool форсировать использование буферизации вывода */ protected $ob = null; /** * Инициализация поля * @return bool */ public function init() { if (! parent::init()) { return false; } $this->setTemplateName('static'); $this->isUnionAllowed = true; return true; } /** * Генерация основного контента поля * @param array $data @ref данные * @return string HTML */ public function view(array &$data = []) { $content = $this->value(); if (is_callable($this->content)) { $handler = [ 'callable' => $this->content, ]; if (! is_null($this->ob)) { $handler['ob'] = $this->ob; } static::obCallable($content, $handler, function ($callable) use ($content, &$data) { return call_user_func($callable, $content, $this, ['data' => &$data]); }); } else if (! empty($this->content)){ $content = $this->content; } $data['content'] = $content; return $this->render($data); } /** * Список полей при построении запроса к БД * @return array */ public function fieldsList() { if (mb_strpos($this->name, static::NONAME_PREFIX) === false) { return parent::fieldsList(); } return []; } }