SilverStripe在保存时编辑gridfield成功消息

时间:2016-07-27 11:39:31

标签: silverstripe

在GridField编辑视图中保存项目时,编辑默认成功消息的最简单方法是什么?

该消息似乎位于方法$message = _t( 'GridFieldDetailForm.Saved', 'Saved {name} {link}', array( 'name' => $this->record->i18n_singular_name(), 'link' => $link ) ); 中的类I think maybe the mongodb's authorization has little hard to understand. This works for me, @Configuration public class MongoConfig { @Value("${mongo.host}") private String host; @Value("#{new Integer('${mongo.port}')}") private Integer port; @Value("${mongo.database}") private String database; @Value("${mongo.username}") private String username; @Value("${mongo.password}") private String password; public @Bean MongoClientFactoryBean mongoDbFactory() throws Exception { MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean(); clientFactoryBean.setHost(host); clientFactoryBean.setPort(port); MongoCredential credential = MongoCredential.createScramSha1Credential(username, database, password.toCharArray()); clientFactoryBean.setCredentials(new MongoCredential[]{credential}); return clientFactoryBean; } public @Bean MongoTemplate mongoTemplate(Mongo mongo) throws Exception { MongoTemplate mongoTemplate = new MongoTemplate(mongo, database); return mongoTemplate; } } --------------------------------- mongo.host=127.0.0.1 mongo.port=27017 mongo.username=hisoka mongo.password=welcome mongo.database=test ---------------------------- Just in mongod cmd create user hisoka for db test, db.createUser({"user":"hisoka","pwd":"welcome","roles":[{role:"readWrite",db:"test"}]}); ------------------------------ Take look in mongoChef, the mongodb auth info: { "_id" : "test.hisoka", "user" : "hisoka", "db" : "test", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : NumberInt(10000), "salt" : "tfXYRbCj6N433PFWJzwarA==", "storedKey" : "pMnNVX7Co7AY7Q4b/dtq18IQfeE=", "serverKey" : "x8vUt590SYVxqW2PW6DA849iTgE=" } }, "roles" : [ { "role" : "readWrite", "db" : "test" } ] } 中的变量中。

COPY

2 个答案:

答案 0 :(得分:3)

由于消息使用_t()函数,因此它将尝试获取与当前用户的语言环境对应的lang文件中定义的值。函数中定义的默认字符串只是在lang文件中找不到翻译时的后备。

要更改消息,您可以更新位于mysite/lang/{LANGUAGE_CODE}.yml

中的网站的yml lang文件

对于英语,这将是:

# 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/

答案 1 :(得分:2)

这样的事情应该适用于特定的实现

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

对于更一般的实现,您可能希望扩展GridFieldDetailForm并覆盖doSave,然后将GridFieldDetailForm组件替换为您的自定义类。