Semicolon
Semicolon

Reputation: 1914

SilverStripe edit gridfield success message on save

What's the easiest way to edit the default success message when saving an item in GridField edit view?

The message seems to be in a variable in class GridFieldDetailForm within method doSave.

$message = _t(
        'GridFieldDetailForm.Saved',
        'Saved {name} {link}',
        array(
            'name' => $this->record->i18n_singular_name(),
            'link' => $link
        )
    );

Upvotes: 3

Views: 204

Answers (2)

Joundill
Joundill

Reputation: 7543

Something like this should work for specific implementations

$form = $gridField->getConfig()->getComponentByType('GridFieldDetailForm');
$form->setItemEditFormCallback(function($form, $itemRequest)
{
    // Replace save action with custom method in here
});

For more general implementations, you'll likely want to extend GridFieldDetailForm and override doSave, then replace the GridFieldDetailForm component with your custom class.

Upvotes: 2

jjjjjjjjjjjjjjjjjjjj
jjjjjjjjjjjjjjjjjjjj

Reputation: 3118

Since the message uses the _t() function it will attempt to fetch the value defined in the lang file corresponding to the current user's locale. The default string defined in the function is just a fallback for when no translation could be found within the lang files.

To change the message you can update your site's yml lang file located in mysite/lang/{LANGUAGE_CODE}.yml

For english this would be:

# mysite/lang/en.yml
# remember to flush after editing me :-)
en:
  GridFieldDetailForm:
    Saved: 'My custom message using {name} and here is a link to the object: {link}'

https://docs.silverstripe.org/en/3.4/developer_guides/i18n/

Upvotes: 3

Related Questions