| Conditions | 2 |
| Paths | 2 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function json(Request $request, Admin $app, $entityName) |
||
| 14 | { |
||
| 15 | $field = $request->getAttribute('field'); |
||
| 16 | $data = $request->getParsedBody(); |
||
| 17 | |||
| 18 | $form = static::createForm($app, $entityName); |
||
| 19 | $form['data'][$field]->val($data['value']); |
||
| 20 | |||
| 21 | if ($form->validate()) { |
||
| 22 | $entity = $app->getEntity($entityName); |
||
| 23 | |||
| 24 | $id = $entity->create($form['data']->val()); |
||
| 25 | $data = $entity->read($id); |
||
| 26 | |||
| 27 | return json_encode([ |
||
| 28 | 'id' => $id, |
||
| 29 | 'label' => $entity->getLabel($id, $data), |
||
| 30 | ]); |
||
| 31 | } |
||
| 32 | |||
| 33 | return Factory::createResponse(400); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |