Skip to content

Commit 27da81d

Browse files
authored
Merge pull request #62 from teamairship/feature/default-values
Feature: Add modifier for Default Values
2 parents a9a21ae + 28dace2 commit 27da81d

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

.github/workflows/pint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build Assets
2+
3+
on: pull_request
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- run: composer update
12+
13+
- run: ./vendor/bin/pint
14+
15+
- run: |
16+
git config --global user.name 'Simon Hamp'
17+
git config --global user.email '[email protected]'
18+
if git add * ; then
19+
git commit -m "Code style fixes"
20+
git push
21+
fi

pint.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"statement_indentation": true
5+
}
6+
}

src/Concerns/HasModifiers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Str;
77
use SimonHamp\LaravelNovaCsvImport\Contracts\Modifier;
88
use SimonHamp\LaravelNovaCsvImport\Modifiers\Boolean;
9+
use SimonHamp\LaravelNovaCsvImport\Modifiers\DefaultValue;
910
use SimonHamp\LaravelNovaCsvImport\Modifiers\ExcelDate;
1011
use SimonHamp\LaravelNovaCsvImport\Modifiers\Hash;
1112
use SimonHamp\LaravelNovaCsvImport\Modifiers\Prefix;
@@ -23,6 +24,7 @@ protected function bootHasModifiers()
2324
// Register built-in modifiers
2425
static::registerModifiers(
2526
new Boolean,
27+
new DefaultValue,
2628
new ExcelDate,
2729
new StrModifier,
2830
new Hash,

src/Modifiers/DefaultValue.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace SimonHamp\LaravelNovaCsvImport\Modifiers;
4+
5+
use SimonHamp\LaravelNovaCsvImport\Contracts\Modifier;
6+
7+
class DefaultValue implements Modifier
8+
{
9+
public function title(): string
10+
{
11+
return 'Default Value';
12+
}
13+
14+
public function description(): string
15+
{
16+
return 'Set a default value for the field if the CSV column is empty or missing';
17+
}
18+
19+
public function settings(): array
20+
{
21+
return [
22+
'string' => [
23+
'type' => 'string',
24+
'title' => 'Default Value',
25+
],
26+
];
27+
}
28+
29+
public function handle($value = null, array $settings = []): string
30+
{
31+
return $value === null ? $settings['string'] : $value;
32+
}
33+
}

0 commit comments

Comments
 (0)