好的,看起来输入的help属性可以用标记填充:
src/Admin/PageAdmin.php:
class PageAdmin extends AbstractAdmin {
// ...
protected function configureFormFields(FormMapper $formMapper) : void
{
/** @var Page $page */
$page = $this->getSubject();
$adminHint = '';
if ($page) {
$adminHint = implode(', ',array_map(function (User $admin) {
return "<strong><a href='/admin/sso/user/{$admin->getId()}/show' target='_blank'>{$admin->getUsername()}</a></strong>";
}, $page->getExplicitAdmins()->toArray()));
}
$formMapper
->add('title', TextType::class)
// ....
->add('admins', ModelAutocompleteType::class, [
'multiple' => true,
'required' => false,
'property' => ['username', 'id'],
'btn_add' => false,
'help' => $adminHint ? "$adminHint have already explicit edit rights (might be inherited from parents). Admins entered here will also get access to all subpages." : "Admins entered here will also get access to all subpages.", // <-- some dynamic content
'help_html' => true, // <-- to enable html rendering
])
}
另见https://symfony.com/bundles/SonataAdminBundle/3.x/cookbook/recipe_image_previews.html。
让我有点烦恼的是,这相当混乱。在这里渲染一个模板会更干净。