在 SonataAdmin 中创建实体后立即执行操作

Do action right after entity created in SonataAdmin

有什么方法可以让我的 SonataAdmin 配置为在默认 CRUD 之后立即执行操作?

情况是,我有一些 classes,每个 class 都有一个 BCode,必须用实体创建。 BCode 是经过调整的 crc32 字符串。所以我需要一个自定义操作才能使用 entity.id

创建此代码

提前致谢

您的管理员 class 扩展了 vendor/sonata-project/admin-bundle/Admin/Admin.php 因此您只需实施方法 postPersistpostUpdate.

如果你使用 doctrine 作为 ORM 你也可以使用 the doctrine events postUpdate and postPersist as described in the documentation.