Feat: Updating Shipping Method with new variables, for correct box env vars
This commit is contained in:
@@ -43,7 +43,7 @@ class ShippingMethodResourceExtension extends ResourceExtension
|
||||
{
|
||||
return array_map(function (Component $component) {
|
||||
if (method_exists($component, 'getName') && $component->getName() === 'name') {
|
||||
return $this->translatedNameField();
|
||||
return self::translatedNameField();
|
||||
}
|
||||
|
||||
if (in_array(HasChildComponents::class, class_uses_recursive($component), true)) {
|
||||
@@ -68,14 +68,28 @@ class ShippingMethodResourceExtension extends ResourceExtension
|
||||
* the model attribute is a string on the way in and out, only ever
|
||||
* an array while Filament's schema state holds it.
|
||||
*/
|
||||
private function translatedNameField(): TranslatedText
|
||||
/**
|
||||
* Also called directly by Modules\Core\Shipping\Extensions\
|
||||
* ShippingMethodListExtension — the create action's form is built
|
||||
* inline by the vendor's ListShippingMethod page rather than through
|
||||
* this class's own extendForm() pipeline, so it needs the same
|
||||
* translated field wired in separately.
|
||||
*/
|
||||
public static function translatedNameField(): TranslatedText
|
||||
{
|
||||
$field = TranslatedText::make('name')
|
||||
->label('Name')
|
||||
->required()
|
||||
->afterStateHydrated(function (TranslatedText $component, $state) {
|
||||
$decoded = json_decode((string) $state, true);
|
||||
$component->state(is_array($decoded) ? $decoded : []);
|
||||
// On create there is no record yet, so Filament hydrates
|
||||
// this from the field's own default/current state — already
|
||||
// an array (or null), never the raw JSON string edit gets
|
||||
// from the model attribute. Only decode when it's a string.
|
||||
if (is_string($state)) {
|
||||
$state = json_decode($state, true);
|
||||
}
|
||||
|
||||
$component->state(is_array($state) ? $state : []);
|
||||
})
|
||||
->dehydrateStateUsing(fn ($state) => json_encode(is_array($state) ? $state : []));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user