/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/widgets/JsonEdit.php
63 строки
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\widgets; use common\assets\JsonEditAsset; use yii\bootstrap\Html; use yii\bootstrap\InputWidget; use yii\helpers\ArrayHelper; /** * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2022 */ class JsonEdit extends InputWidget { /** * @inheritdoc */ public function init() { parent::init(); if ($this->hasModel()) { $this->name = ArrayHelper::getValue($this->options, 'name', Html::getInputName($this->model, $this->attribute)); } } /** * @inheritdoc */ public function run() { if ($this->hasModel()) { $json = Html::getAttributeValue($this->model, $this->attribute); } else { $json = $this->value; } $this->registerClientScript(); echo $this->render('json_edit.twig', [ 'id' => $this->options['id'], 'readonly' => ArrayHelper::getValue($this->options, 'readonly'), 'class' => ArrayHelper::getValue($this->options, 'modal') ? 'json-modal' : 'json-form', 'name' => $this->name, 'json_name' => md5($this->name), 'hidden_name' => md5($this->name . '-hidden'), 'value' => $json, ]); } /** * Registers jsonEditor js plugin */ protected function registerClientScript() { $view = $this->getView(); // подключаем редактор $asset = JsonEditAsset::register($view); } }