Skip to content

Commit

Permalink
Merge pull request #289 from germanbisurgi/dev/devgroup-alternative
Browse files Browse the repository at this point in the history
Dev/devgroup alternative
  • Loading branch information
schmunk42 committed Jan 12, 2023
2 parents 1e6f16a + fdd0902 commit 4c021ca
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"homepage": "http://www.usrbin.de"
}
],
"suggest": {
"kdn/yii2-json-editor": "JSON editor widget for Yii 2."
},
"require": {
"cmrcx/phptidy": "^3.1",
"dmstr/yii2-bootstrap": "^0.1.2 || ^0.2.1",
Expand Down
5 changes: 1 addition & 4 deletions src/generators/crud/callbacks/devgroup/Jsoneditor.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
/**
* Created by PhpStorm.
* User: tobias
* Date: 09.06.15
* Time: 22:40.
* Deprecated. Use schmunk42\giiant\generators\crud\callbacks\kdn\Jsoneditor instead
*/
namespace schmunk42\giiant\generators\crud\callbacks\devgroup;

Expand Down
69 changes: 69 additions & 0 deletions src/generators/crud/callbacks/kdn/Jsoneditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Created by PhpStorm.
* User: tobias
* Date: 09.06.15
* Time: 22:40.
*/
namespace schmunk42\giiant\generators\crud\callbacks\kdn;

use yii\helpers\Inflector;

class Jsoneditor
{
public static function field()
{
return function ($attribute) {
$editor = \kdn\yii2\JsonEditor::class;
$label = Inflector::camelize($attribute);

return <<<FORMAT
'<div class="form-group field-widget-{$attribute}"><label class="control-label col-sm-2">{$label}</label><div class="col-sm-8">'.
{$editor}::widget(
[
'clientOptions' => [
'modes' => ['code', 'form', 'text', 'tree', 'view'],
'mode' => 'tree',
],
'model' => \$model,
'attribute' => '{$attribute}',
'options' => [
'id' => 'widget-{$attribute}',
'class' => 'form-control',
]
]
).
'</div></div>'
FORMAT;
};
}

public static function attribute()
{
return function ($attribute, $generator) {
$method = __METHOD__;
$editor = \kdn\yii2\JsonEditor::class;
return <<<FORMAT
// generated by {$method}
[
'format' => 'raw',
'attribute' => '{$attribute}',
'headerOptions' => ['style' => 'min-width: 600px'],
'value'=> function (\$model) {
return {$editor}::widget([
'name' => '_display',
'value' => \$model->{$attribute},
'clientOptions' => [
'mode' => 'view',
'modes' => [
'view',
'code'
]
]
]);
}
]
FORMAT;
};
}
}

0 comments on commit 4c021ca

Please sign in to comment.