Skip to content

Commit

Permalink
Add support for Statamic 5 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni authored May 9, 2024
1 parent 25490b7 commit d0f9732
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.2, 8.3]
laravel: [10.*]
laravel: [10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"require": {
"php": "^8.2",
"jonassiewertsen/statamic-livewire": "^3.0",
"laravel/framework": "^10.0",
"laravel/framework": "^10.0 || ^11.0",
"laravel/prompts": "^0.1.13",
"livewire/livewire": "^3.2",
"spatie/invade": "^2.0",
"statamic/cms": "^4.9"
"statamic/cms": "^5.0"
},
"require-dev": {
"orchestra/testbench": "^8.19",
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/MakeTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Statamic\Console\RunsInPlease;

use function Laravel\Prompts\confirm;
Expand All @@ -21,7 +22,7 @@ class MakeTheme extends Command
public function handle(): void
{
$name = $this->argument('name') ?? text(label: 'What do you want to name the theme?', required: true);
$path = resource_path('views/'.config('livewire-forms.view_path').'/'.snake_case($name));
$path = resource_path('views/'.config('livewire-forms.view_path').'/'.Str::snake($name));

if (! File::exists($path) || confirm(label: 'A theme with this name already exists. Do you want to overwrite it?', default: false)) {
File::copyDirectory(__DIR__.'/../../resources/views/default/', $path);
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/MakeView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Statamic\Console\RunsInPlease;

use function Laravel\Prompts\confirm;
Expand All @@ -22,7 +23,7 @@ public function handle(): void
{
$name = $this->argument('name') ?? text(label: 'What do you want to name the view?', required: true);
$stub = File::get(__DIR__.'/../../resources/views/default.blade.php');
$filename = str_slug($name).'.blade.php';
$filename = Str::slug($name).'.blade.php';
$path = resource_path('views/'.config('livewire-forms.view_path')."/{$filename}");

if (! File::exists($path) || confirm(label: 'A view with this name already exists. Do you want to overwrite it?', default: false)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Fields/Properties/WithRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Aerni\LivewireForms\Fields\Properties;

use Illuminate\Support\Arr;
use Statamic\Fields\Validator;

trait WithRules
{
protected function rulesProperty(string|array|null $rules = null): array
{
$rules = is_null($rules)
? array_flatten($this->field->rules())
? Arr::flatten($this->field->rules())
: Validator::explodeRules($rules);

return [$this->key => $rules];
Expand Down
3 changes: 2 additions & 1 deletion src/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Aerni\LivewireForms\Fields\Properties\WithMultiple;
use Aerni\LivewireForms\Fields\Properties\WithOptions;
use Aerni\LivewireForms\Fields\Properties\WithPlaceholder;
use Illuminate\Support\Arr;

class Select extends Field
{
Expand Down Expand Up @@ -45,7 +46,7 @@ protected function defaultProperty(mixed $default = null): string|array|null

protected function rulesProperty(string|array|null $rules = null): array
{
$rules = array_first(parent::rulesProperty($rules));
$rules = Arr::first(parent::rulesProperty($rules));

if ($this->multiple && $this->max_items) {
$rules[] = "max:{$this->max_items}";
Expand Down
3 changes: 2 additions & 1 deletion src/Fields/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Aerni\LivewireForms\Fields;

use Aerni\LivewireForms\Fields\Properties\WithInlineLabel;
use Illuminate\Support\Arr;

class Toggle extends Field
{
Expand All @@ -12,7 +13,7 @@ class Toggle extends Field

protected function rulesProperty(string|array|null $rules = null): array
{
$rules = array_first(parent::rulesProperty($rules));
$rules = Arr::first(parent::rulesProperty($rules));

if (in_array('required', $rules)) {
$rules[] = 'accepted';
Expand Down
3 changes: 2 additions & 1 deletion src/Livewire/Concerns/HandlesValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Aerni\LivewireForms\Livewire\Concerns;

use Illuminate\Support\Arr;
use Livewire\Attributes\Locked;

trait HandlesValidation
Expand Down Expand Up @@ -45,7 +46,7 @@ public function bootHandlesValidation(): void

public function resetStepErrorBag(string|array $keys): void
{
array_forget($this->stepErrors, $keys);
Arr::forget($this->stepErrors, $keys);

$this->setErrorBag($this->stepErrors);
}
Expand Down

0 comments on commit d0f9732

Please sign in to comment.