Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Issue Fix #902 (#909)
Browse files Browse the repository at this point in the history
* Issue fix #902

* Add migration for allow value nullable in settings table

* Set texttype for value field
  • Loading branch information
binal-7span committed Apr 26, 2019
1 parent d3d8662 commit 20e5fb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
@@ -0,0 +1,15 @@
<?php

use Phinx\Migration\AbstractMigration;

class SetNullableValueFieldSettingsTable extends AbstractMigration
{
public function up()
{
$table = $this->table('directus_settings');

$table->changeColumn('value', 'text', [
'null' => true
]);
}
}
29 changes: 18 additions & 11 deletions src/endpoints/Settings.php
Expand Up @@ -83,7 +83,7 @@ public function all(Request $request, Response $response)
*
*/
foreach($fieldData['data'] as $key => $value){
switch ($value['interface']) {
switch ($value['type']) {
case 'file':
$result = array_search($value['field'], array_column($responseData['data'], 'key'));
if($result){
Expand All @@ -95,7 +95,7 @@ public function all(Request $request, Response $response)
}
}
break;
case 'tags':
case 'array':
$inputData['value'] = !empty($responseData['data'][$result]['value']) ? $responseData['data'][$result]['value'] : null;
break;
}
Expand Down Expand Up @@ -153,13 +153,21 @@ public function getInterfaceBasedInput($request,$setting)
$inputData = $request->getParsedBody();
foreach($fieldData['data'] as $key => $value){
if($value['field'] == $setting){
switch ($value['interface']) {
case 'file':
$inputData['value'] = isset($inputData['value']['id']) ? $inputData['value']['id'] : $inputData['value'];
break;
case 'tags':
$inputData['value'] = is_array($inputData['value']) ? implode(",",$inputData['value']) : $inputData['value'];
break;
if($inputData['value'] != null){
switch ($value['type']) {
case 'file':
$inputData['value'] = isset($inputData['value']['id']) ? $inputData['value']['id'] : $inputData['value'];
break;
case 'array':
$inputData['value'] = is_array($inputData['value']) ? implode(",",$inputData['value']) : $inputData['value'];
break;
case 'json':
$inputData['value'] = json_encode($inputData['value']);
break;
}
}else{
// To convert blank string in null
$inputData['value'] = null;
}
}
}
Expand All @@ -174,8 +182,6 @@ public function getInterfaceBasedInput($request,$setting)
*/
public function update(Request $request, Response $response)
{
$this->validateRequestPayload($request);

$payload = $request->getParsedBody();
$id = $request->getAttribute('id');

Expand All @@ -199,6 +205,7 @@ public function update(Request $request, Response $response)
* Get the interface based input
*
*/

$inputData = $this->getInterfaceBasedInput($request,$serviceData['data']['key']);
$responseData = $service->update(
$request->getAttribute('id'),
Expand Down

0 comments on commit 20e5fb6

Please sign in to comment.