Change the default "save and create another" label in modal form

Hello all 👋, I have a resource (MarketingMessage) for which I removed the default pages CreateMarketingMessage.php and EditMarketingMessage.php to have Modals instead. So, in my resource's getPages() method, I have just one value in the return array:
public static function getPages(): array
{
return [
index' => Pages\ListMarketingMessages::route('/'),
];
}
public static function getPages(): array
{
return [
index' => Pages\ListMarketingMessages::route('/'),
];
}
Everything works fine, but I wanted to know which method I should use (and where) to change the default label of “Create & add another”. Because in French, I have to change the translation to use a feminine form. I saw that there was a getCreateAnotherFormAction() method to use in CreateMarketingMessage.php, but since I don't use that page, it's no good. Can anyone help me? I couldn't find a reference in the documentation. Thanks in advance 😇
7 Replies
Vp
Vp6mo ago
https://filamentphp.com/docs/3.x/actions/modals#adding-an-extra-modal-action-button-to-the-footer
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label('New label'),
])
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label('New label'),
])
Vp
Vp6mo ago
You've to apply this on CreateAction in ListRecord
Alexandre
AlexandreOP6mo ago
Thanks for your answer. In where method should I put this? I can't find something related in the base ListRecords.php file. I tried to use this method, but I don't think is the good one because nothing change :
protected function configureCreateAction(CreateAction|Tables\Actions\CreateAction $action): void
{
$resource = static::getResource();

$action
->authorize($resource::canCreate())
->model($this->getModel())
->modelLabel($this->getModelLabel() ?? static::getResource()::getModelLabel())
->form(fn(Form $form): Form => $this->form($form->columns(2)));

if (($action instanceof CreateAction) && static::getResource()::isScopedToTenant()) {
$action->relationship(($tenant = Filament::getTenant()) ? fn(
): Relation => static::getResource()::getTenantRelationship($tenant) : null);
}

if ($resource::hasPage('create')) {
$action->url(fn(): string => $resource::getUrl('create'));
}

// Here
if ($action instanceof CreateAction) {
$action->extraModalFooterActions(function (Action $action): array {
return [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label('My new label'),
];
});
}
}
protected function configureCreateAction(CreateAction|Tables\Actions\CreateAction $action): void
{
$resource = static::getResource();

$action
->authorize($resource::canCreate())
->model($this->getModel())
->modelLabel($this->getModelLabel() ?? static::getResource()::getModelLabel())
->form(fn(Form $form): Form => $this->form($form->columns(2)));

if (($action instanceof CreateAction) && static::getResource()::isScopedToTenant()) {
$action->relationship(($tenant = Filament::getTenant()) ? fn(
): Relation => static::getResource()::getTenantRelationship($tenant) : null);
}

if ($resource::hasPage('create')) {
$action->url(fn(): string => $resource::getUrl('create'));
}

// Here
if ($action instanceof CreateAction) {
$action->extraModalFooterActions(function (Action $action): array {
return [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label('My new label'),
];
});
}
}
Vp
Vp6mo ago
Like this
No description
Solution
Vp
Vp6mo ago
No description
Vp
Vp6mo ago
Alexandre
AlexandreOP6mo ago
Thanks you, that it! So, what I did is put that on the getHeaderActions() method in my List resource page :
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->extraModalFooterActions(fn(Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('marketingMessages.actions.create_another')),
]),
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()
->extraModalFooterActions(fn(Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label(__('marketingMessages.actions.create_another')),
]),
];
}
Thanks you for your help 🙂
Want results from more Discord servers?
Add your server