FEATURE: make adding custom fields working
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\CustomFieldTypes;
|
||||
use App\Http\Requests\NewCustomFieldRequest;
|
||||
use App\Models\CustomField;
|
||||
|
||||
class CreateNewCustomField extends Controller
|
||||
{
|
||||
@@ -16,5 +17,41 @@ class CreateNewCustomField extends Controller
|
||||
|
||||
public function postNew(NewCustomFieldRequest $request)
|
||||
{
|
||||
$customField = new CustomField();
|
||||
|
||||
// @todo add support for determination of resource for custom field (module, user, ...)
|
||||
// @todo add possible values
|
||||
|
||||
$customField->name = $request->name;
|
||||
$customField->type_id = $request->type;
|
||||
$customField->required = $request->has('required');
|
||||
|
||||
// set non-mandatory fields
|
||||
|
||||
if ($request->description) {
|
||||
$customField->description = $request->description;
|
||||
}
|
||||
|
||||
if ($request->defaultValue) {
|
||||
$customField->default_value = $request->defaultValue;
|
||||
}
|
||||
|
||||
if ($request->regExp) {
|
||||
$customField->regexp = $request->regExp;
|
||||
}
|
||||
|
||||
if ($request->minLength) {
|
||||
$customField->min_length = $request->minLength;
|
||||
}
|
||||
|
||||
if ($request->maxLength) {
|
||||
$customField->max_length = $request->maxLength;
|
||||
}
|
||||
|
||||
$customField->save();
|
||||
|
||||
return redirect()
|
||||
->route('customfields.new')
|
||||
->with('success', trans('admin/customFields.successfullyCreated'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ class NewCustomFieldRequest extends Request
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'type' => 'required|exists:custom_field_types',
|
||||
'type' => 'required|exists:custom_field_types,id',
|
||||
'minLength' => 'numeric|min:0',
|
||||
'maxLength' => 'numeric|mix:0'
|
||||
'maxLength' => 'numeric|min:0',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
<?php
|
||||
return [
|
||||
'overview' => 'List of all custom fields',
|
||||
'new' => 'New custom field',
|
||||
'noFields' => 'No custom fields defined.',
|
||||
'users' => 'Custom fields for user',
|
||||
'content' => 'Custom fields for content page',
|
||||
'name' => 'Name',
|
||||
'description' => 'Description',
|
||||
'type' => 'Type of custom field',
|
||||
'required' => 'Is field required?',
|
||||
'defaultValue' => 'Default value',
|
||||
'regExp' => 'Match only this regular expression',
|
||||
'minLength' => 'Minimum length',
|
||||
'maxLength' => 'Maximum length',
|
||||
'createNew' => 'Create new field',
|
||||
'date' => 'Date',
|
||||
'number' => 'Number',
|
||||
'selectboxList' => 'List (selectbox)',
|
||||
'string' => 'Short text'
|
||||
'overview' => 'List of all custom fields',
|
||||
'new' => 'New custom field',
|
||||
'noFields' => 'No custom fields defined.',
|
||||
'users' => 'Custom fields for user',
|
||||
'content' => 'Custom fields for content page',
|
||||
'name' => 'Name',
|
||||
'description' => 'Description',
|
||||
'type' => 'Type of custom field',
|
||||
'required' => 'Is field required?',
|
||||
'defaultValue' => 'Default value',
|
||||
'regExp' => 'Match only this regular expression',
|
||||
'minLength' => 'Minimum length',
|
||||
'maxLength' => 'Maximum length',
|
||||
'createNew' => 'Create new field',
|
||||
'date' => 'Date',
|
||||
'number' => 'Number',
|
||||
'selectboxList' => 'List (selectbox)',
|
||||
'string' => 'Short text',
|
||||
'successfullyCreated' => 'Custom field successfully created.'
|
||||
];
|
||||
@@ -10,6 +10,17 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@if (session('success'))
|
||||
<div data-alert class="callout success">
|
||||
<strong>{{ session('success') }}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (session('error'))
|
||||
<div data-alert class="callout alert">
|
||||
<strong>{{ session('error') }}</strong>
|
||||
</div>
|
||||
@endif
|
||||
@include('admin.customFields.newForm')
|
||||
</div>
|
||||
@stop
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="large-6 columns">
|
||||
<label>
|
||||
@lang('admin/customFields.name')
|
||||
<input type="text" placeholder="@lang('admin/customFields.name')" name="name">
|
||||
<input type="text" placeholder="@lang('admin/customFields.name')" value="{{old('name')}}" name="name">
|
||||
|
||||
@if (isset($errors) && $errors->has('name'))
|
||||
<div class="callout alert">
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<select name="type">
|
||||
@foreach($types as $type => $translation)
|
||||
<option value="{{$type}}">@lang($translation)</option>
|
||||
<option value="{{$type}}"@if(old('type') == $type) selected @endif>@lang($translation)</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<label>
|
||||
@lang('admin/customFields.description')
|
||||
|
||||
<textarea rows="5" name="description" placeholder="@lang('admin/customFields.description')"></textarea>
|
||||
<textarea rows="5" name="description" placeholder="@lang('admin/customFields.description')">{{old('description')}}</textarea>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@@ -45,19 +45,19 @@
|
||||
<label>
|
||||
@lang('admin/customFields.required')
|
||||
|
||||
<input type="checkbox" placeholder="@lang('admin/customFields.required')" name="required">
|
||||
<input type="checkbox" placeholder="@lang('admin/customFields.required')" @if (old('required')) checked="checked" @endif name="required">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('admin/customFields.defaultValue')
|
||||
|
||||
<input type="text" placeholder="@lang('admin/customFields.defaultValue')" name="defaultValue">
|
||||
<input type="text" placeholder="@lang('admin/customFields.defaultValue')" value="{{old('defaultValue')}}" name="defaultValue">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('admin/customFields.regExp')
|
||||
|
||||
<input type="text" placeholder="@lang('admin/customFields.regExp')" name="regExp">
|
||||
<input type="text" placeholder="@lang('admin/customFields.regExp')" value="{{old('regExp')}}" name="regExp">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -67,7 +67,7 @@
|
||||
<label>
|
||||
@lang('admin/customFields.minLength')
|
||||
|
||||
<input type="text" placeholder="@lang('admin/customFields.minLength')" name="minLength">
|
||||
<input type="text" placeholder="@lang('admin/customFields.minLength')" value="{{old('minLength')}}" name="minLength">
|
||||
|
||||
@if (isset($errors) && $errors->has('minLength'))
|
||||
<div class="callout alert">
|
||||
@@ -80,7 +80,7 @@
|
||||
<label>
|
||||
@lang('admin/customFields.maxLength')
|
||||
|
||||
<input type="text" placeholder="@lang('admin/customFields.maxLength')" name="maxLength">
|
||||
<input type="text" placeholder="@lang('admin/customFields.maxLength')" value="{{old('macLength')}}" name="maxLength">
|
||||
|
||||
@if (isset($errors) && $errors->has('maxLength'))
|
||||
<div class="callout alert">
|
||||
|
||||
Reference in New Issue
Block a user