Skip to content

Commit bd8e591

Browse files
committed
Export fields of model as JSON
1 parent cf24bc3 commit bd8e591

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"homepage": "https://github.com/phpzm/model",
1212
"license": "MIT",
13-
"version": "1.0.0",
13+
"version": "1.0.1",
1414
"type": "package",
1515
"authors": [
1616
{

src/DataMapper.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Simples\Data\Collection;
66
use Simples\Data\Error\SimplesResourceError;
77
use Simples\Data\Record;
8+
use Simples\Helper\JSON;
89
use Simples\Model\Error\SimplesActionError;
910
use Simples\Model\Error\SimplesHookError;
1011
use Simples\Model\Resources\ModelParser;
@@ -318,4 +319,33 @@ protected function getActionFields(string $action, bool $strict = true)
318319
}
319320
return $fields;
320321
}
322+
323+
/**
324+
* @return string
325+
*/
326+
public function getJSON()
327+
{
328+
$fields = [];
329+
/** @var Field $field */
330+
foreach ($this->fields as $field) {
331+
$fields[] = [
332+
'field' => $field->getName(),
333+
'type' => $field->getType(),
334+
'label' => $field->option('label'),
335+
'grid' => true,
336+
'form' => ['create', 'show', 'edit'],
337+
'search' => true,
338+
'grids' => [
339+
'width' => ''
340+
],
341+
'forms' => [
342+
'component' => '',
343+
'width' => '',
344+
'disabled' => false,
345+
'order' => 0
346+
]
347+
];
348+
}
349+
return JSON::encode($fields);
350+
}
321351
}

0 commit comments

Comments
 (0)