Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f43ecb
generalize how field state is handled in filament
repl6669 Feb 14, 2025
739d28c
add edit product test
repl6669 Feb 14, 2025
e64c382
Merge branch '1.x' into feat/generalize-attribute-data-handling-in-fi…
repl6669 May 13, 2025
fbfd56c
chore: fix code style
actions-user May 13, 2025
4841042
Update facade docblocks
repl6669 Jul 2, 2025
88c80d1
Merge branch 'lunarphp:1.x' into 1.x
repl6669 Aug 18, 2025
9cdb272
Merge branch '1.x' into feat/generalize-attribute-data-handling-in-fi…
repl6669 Aug 18, 2025
09c5e4a
test that all attribute data fields render correctly
repl6669 Aug 18, 2025
303b033
test custom repeater field
repl6669 Aug 18, 2025
9f17116
update attribute data
repl6669 Aug 18, 2025
47a934f
add custom builder field stubs
repl6669 Aug 18, 2025
64d414c
test custom builder field
repl6669 Aug 18, 2025
5bba165
update gitignore
repl6669 Aug 18, 2025
0a9b6c7
fix typo
repl6669 Aug 27, 2025
e64a262
update repeater field stub
repl6669 Aug 27, 2025
95d31dd
update builder synth
repl6669 Aug 27, 2025
70120e5
update test
repl6669 Aug 27, 2025
c406777
update attribute data
repl6669 Aug 27, 2025
f7630a1
Merge branch 'lunarphp:1.x' into feat/generalize-attribute-data-handl…
repl6669 Aug 27, 2025
9ebe5a2
Merge branch 'lunarphp:1.x' into feat/generalize-attribute-data-handl…
repl6669 Sep 12, 2025
3efa33c
Merge branch '1.x' into feat/generalize-attribute-data-handling-in-fi…
glennjacobs Nov 10, 2025
81d165a
Merge branch '1.x' into feat/generalize-attribute-data-handling-in-fi…
glennjacobs Nov 11, 2025
6343fe6
chore: fix code style
actions-user Nov 11, 2025
3f2e043
Merge branch '1.x' into feat/generalize-attribute-data-handling-in-fi…
glennjacobs Nov 11, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/.idea
/.nova
/.phpunit.cache
/.phpactor.json
/.vscode
/node_modules
/vendor
Expand Down
46 changes: 23 additions & 23 deletions packages/admin/src/Support/Forms/AttributeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
use Lunar\Admin\Support\FieldTypes\TranslatedText;
use Lunar\Admin\Support\FieldTypes\Vimeo;
use Lunar\Admin\Support\FieldTypes\YouTube;
use Lunar\FieldTypes\Dropdown as DrodownFieldType;
use Lunar\Base\FieldType as FieldTypeContract;
use Lunar\FieldTypes\Dropdown as DropdownFieldType;
use Lunar\FieldTypes\File as FileFieldType;
use Lunar\FieldTypes\ListField as ListFieldFieldType;
use Lunar\FieldTypes\Number as NumberFieldType;
Expand All @@ -27,7 +28,7 @@
class AttributeData
{
protected array $fieldTypes = [
DrodownFieldType::class => Dropdown::class,
DropdownFieldType::class => Dropdown::class,
ListFieldFieldType::class => ListField::class,
TextFieldType::class => TextField::class,
TranslatedTextFieldType::class => TranslatedText::class,
Expand All @@ -40,26 +41,26 @@ class AttributeData

public function getFilamentComponent(Attribute $attribute): Component
{
$fieldType = $this->fieldTypes[
$attribute->type
] ?? TextField::class;
$fieldType = $this->fieldTypes[$attribute->type] ?? TextField::class;

/** @var Component $component */
$component = $fieldType::getFilamentComponent($attribute);

return $component
->label(
$attribute->translate('name')
)
->label($attribute->translate('name'))
->formatStateUsing(function ($state) use ($attribute) {
if (
! $state ||
(get_class($state) != $attribute->type)
) {
return new $attribute->type;
if (! $state instanceof FieldTypeContract || (get_class($state) !== $attribute->type)) {
$state = new $attribute->type;
}

return $state;
$value = $state->getValue();

// Only normalize nested-array states (e.g. repeater/builder), preserve scalar lists
if (is_array($state) && $state !== [] && is_array(reset($state))) {
$state = array_values(array_filter($state, 'is_array'));
}

return $value;
})
->mutateStateForValidationUsing(function ($state) {
if ($state instanceof \Lunar\Base\FieldType) {
Expand All @@ -69,18 +70,17 @@ public function getFilamentComponent(Attribute $attribute): Component
return $state;
})
->mutateDehydratedStateUsing(function ($state) use ($attribute) {
if ($attribute->type == FileFieldType::class) {
$instance = new $attribute->type;
$instance->setValue($state);

return $instance;
// Normalize arrays before wrapping into FieldType instance
if (is_array($state)) {
$state = array_values(array_filter($state, 'is_array'));
}

if (
! $state ||
(get_class($state) != $attribute->type)
) {
return new $attribute->type;
if (! $state instanceof FieldTypeContract || ! ($state instanceof $attribute->type)) {
$field = (new $attribute->type);
$field->setValue($state);

return $field;
}

return $state;
Expand Down
23 changes: 12 additions & 11 deletions packages/core/src/Facades/StorefrontSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
use Lunar\Base\StorefrontSessionInterface;

/**
* @method static void forget()
* @method static void initCustomerGroups()
* @method static void initChannel()
* @method static \Lunar\Models\Contracts\Customer|null initCustomer()
* @method static string getSessionKey()
* @method static \Lunar\Managers\StorefrontSessionManager setChannel(\Lunar\Models\Contracts\Channel|string $channel)
* @method static \Lunar\Managers\StorefrontSessionManager setCustomer(\Lunar\Models\Contracts\Customer $customer)
* @method static \Lunar\Models\Contracts\Customer|null getCustomer()
* @method static \Lunar\Models\Contracts\Channel getChannel()
* @method static \Lunar\Managers\StorefrontSessionManager setChannel(\Lunar\Models\Contracts\Channel $channel)
* @method static \Illuminate\Support\Collection getCustomerGroups()
* @method static \Lunar\Managers\StorefrontSessionManager setCustomerGroups(\Illuminate\Support\Collection $customerGroups)
* @method static \Lunar\Managers\StorefrontSessionManager setCustomerGroup(\Lunar\Models\Contracts\CustomerGroup $customerGroup)
* @method static \Lunar\Managers\StorefrontSessionManager resetCustomerGroups()
* @method static \Lunar\Models\Contracts\Channel getChannel()
* @method static \Illuminate\Support\Collection|null getCustomerGroups()
* @method static \Lunar\Managers\StorefrontSessionManager setCurrency(\Lunar\Models\Contracts\Currency $currency)
* @method static \Lunar\Models\Contracts\Currency getCurrency()
* @method static \Lunar\Managers\StorefrontSessionManager setCurrency(\Lunar\Models\Contracts\Currency $currency)
* @method static \Lunar\Models\Contracts\Customer|null getCustomer()
* @method static \Lunar\Managers\StorefrontSessionManager setCustomer(\Lunar\Models\Contracts\Customer $customer)
* @method static void initChannel()
* @method static void initCustomerGroups()
* @method static void initCurrency()
* @method static void initCustomer()
* @method static void forget()
* @method static string getSessionKey()
*
* @see \Lunar\Managers\StorefrontSessionManager
*/
Expand Down
Loading