Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
613 changes: 309 additions & 304 deletions composer.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/Enums/ListableOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tdwesten\StatamicBuilder\Enums;

enum ListableOption: string
{
case Hidden = 'hidden';
case True = 'true';
case False = 'false';

public function toArray(): bool|string
{
return match ($this) {
ListableOption::Hidden => 'hidden',
ListableOption::True => true,
ListableOption::False => false,
};
}
}
9 changes: 5 additions & 4 deletions src/FieldTypes/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Tdwesten\StatamicBuilder\Contracts\Makeble;
use Tdwesten\StatamicBuilder\Contracts\Renderable;
use Tdwesten\StatamicBuilder\Enums\Icon;
use Tdwesten\StatamicBuilder\Enums\ListableOption;
use Tdwesten\StatamicBuilder\Enums\VisibilityOption;
use Tdwesten\StatamicBuilder\Exceptions\BlueprintRenderException;
use Tdwesten\StatamicBuilder\Helpers\FieldParser;
Expand All @@ -32,7 +33,7 @@ class Field implements Renderable

protected $instructionsPosition = 'above';

protected $listable = 'visible';
protected $listable = ListableOption::Hidden;

protected $replicatorPreview = true;

Expand Down Expand Up @@ -106,7 +107,7 @@ public function fieldDefaults(): Collection
'icon' => $this->icon?->value,
'instructions' => $this->instructions,
'instructions_position' => $this->instructionsPosition,
'listable' => $this->listable,
'listable' => $this->listable->toArray(),
Copy link
Owner

@tdwesten tdwesten Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you can use here $this->listable->value :)

'replicator_preview' => $this->replicatorPreview,
'required' => $this->required,
'type' => $this->type,
Expand Down Expand Up @@ -225,9 +226,9 @@ public function instructionsPositionBelow()
return $this;
}

public function listable()
public function listable(?ListableOption $listable = null)
{
$this->listable = true;
$this->listable = $listable ?? ListableOption::True;

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'hide_display' => false,
'input_type' => 'text',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'replicator_preview' => true,
'type' => 'text',
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/FieldTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Tdwesten\StatamicBuilder\Enums\Icon;
use Tdwesten\StatamicBuilder\Enums\ListableOption;
use Tdwesten\StatamicBuilder\Enums\VisibilityOption;

it('can render to a array', function (): void {
Expand Down Expand Up @@ -76,7 +77,7 @@

test('Can set listable', function (): void {
$field = new \Tdwesten\StatamicBuilder\FieldTypes\Field('title');
$field->listable();
$field->listable(ListableOption::True);

expect($field->toArray()['field']['listable'])->toBe(true);
});
Expand Down
18 changes: 12 additions & 6 deletions tests/Unit/Fields/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
->visibility(VisibilityOption::Visible)
->listable()
->width(33),
])->displayName('Call to Action');
])
->displayName('Call to Action')
->listable();

$expected = [
'handle' => 'cta',
Expand Down Expand Up @@ -43,7 +45,7 @@
'fullscreen' => false,
'hide_display' => false,
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => true,
'localizable' => false,
'replicator_preview' => true,
'type' => 'group',
Expand All @@ -64,8 +66,12 @@
->visibility(VisibilityOption::Visible)
->listable()
->width(33),
])->displayName('Call to Action'),
])->displayName('Call to Action');
])
->displayName('Call to Action')
->listable(),
])
->displayName('Call to Action')
->listable();

$expected = [
'handle' => 'counties',
Expand Down Expand Up @@ -102,7 +108,7 @@
'fullscreen' => false,
'hide_display' => false,
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => true,
'localizable' => false,
'replicator_preview' => true,
'type' => 'group',
Expand All @@ -113,7 +119,7 @@
'fullscreen' => false,
'hide_display' => false,
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => true,
'localizable' => false,
'replicator_preview' => true,
'type' => 'group',
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Fields/ReplicatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
'fullscreen' => true,
'hide_display' => false,
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'previews' => true,
'replicator_preview' => true,
Expand All @@ -80,7 +80,7 @@
'hide_display' => false,
'input_type' => 'text',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'replicator_preview' => true,
'type' => 'text',
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Fields/TermsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'hide_display' => false,
'instructions' => 'The counties of the school',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'mode' => 'default',
'replicator_preview' => true,
Expand Down Expand Up @@ -56,7 +56,7 @@
'hide_display' => false,
'instructions' => 'The counties of the school',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'max_items' => 5,
'mode' => 'default',
Expand Down Expand Up @@ -93,7 +93,7 @@
'hide_display' => false,
'instructions' => 'The counties of the school',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'mode' => 'default',
'replicator_preview' => true,
Expand Down Expand Up @@ -131,7 +131,7 @@
'hide_display' => false,
'instructions' => 'The counties of the school',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'mode' => 'select',
'replicator_preview' => true,
Expand Down Expand Up @@ -170,7 +170,7 @@
'hide_display' => false,
'instructions' => 'The counties of the school',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => 'hidden',
'localizable' => false,
'mode' => 'select',
'replicator_preview' => true,
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Fields/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
->required()
->instructions('The name of the county')
->instructionsPosition('above')
->antlers(false);
->antlers(false)
->listable();

$expected = [
'handle' => 'title',
Expand All @@ -67,7 +68,7 @@
'input_type' => 'text',
'instructions' => 'The name of the county',
'instructions_position' => 'above',
'listable' => 'visible',
'listable' => true,
'localizable' => false,
'replicator_preview' => true,
'required' => true,
Expand Down