Skip to content

Commit

Permalink
Merge pull request #62 from teamairship/feature/default-values
Browse files Browse the repository at this point in the history
Feature: Add modifier for Default Values
  • Loading branch information
simonhamp authored Apr 24, 2023
2 parents a9a21ae + 28dace2 commit 27da81d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build Assets

on: pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: composer update

- run: ./vendor/bin/pint

- run: |
git config --global user.name 'Simon Hamp'
git config --global user.email 'simon.hamp@me.com'
if git add * ; then
git commit -m "Code style fixes"
git push
fi
6 changes: 6 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"preset": "laravel",
"rules": {
"statement_indentation": true
}
}
2 changes: 2 additions & 0 deletions src/Concerns/HasModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Str;
use SimonHamp\LaravelNovaCsvImport\Contracts\Modifier;
use SimonHamp\LaravelNovaCsvImport\Modifiers\Boolean;
use SimonHamp\LaravelNovaCsvImport\Modifiers\DefaultValue;
use SimonHamp\LaravelNovaCsvImport\Modifiers\ExcelDate;
use SimonHamp\LaravelNovaCsvImport\Modifiers\Hash;
use SimonHamp\LaravelNovaCsvImport\Modifiers\Prefix;
Expand All @@ -23,6 +24,7 @@ protected function bootHasModifiers()
// Register built-in modifiers
static::registerModifiers(
new Boolean,
new DefaultValue,
new ExcelDate,
new StrModifier,
new Hash,
Expand Down
33 changes: 33 additions & 0 deletions src/Modifiers/DefaultValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace SimonHamp\LaravelNovaCsvImport\Modifiers;

use SimonHamp\LaravelNovaCsvImport\Contracts\Modifier;

class DefaultValue implements Modifier
{
public function title(): string
{
return 'Default Value';
}

public function description(): string
{
return 'Set a default value for the field if the CSV column is empty or missing';
}

public function settings(): array
{
return [
'string' => [
'type' => 'string',
'title' => 'Default Value',
],
];
}

public function handle($value = null, array $settings = []): string
{
return $value === null ? $settings['string'] : $value;
}
}

0 comments on commit 27da81d

Please sign in to comment.