EasyAdmin 头像字段
此字段显示一个代表用户头像的图片,头像基于某个实体属性的值。
在 表单页面(编辑和新建) 中,它在 <input type="text">
字段中渲染头像图片 URL。在只读页面(index
和 detail
)中,它渲染由该 URL 表示的 <img>
元素。
基本信息
- PHP 类:
EasyCorp
\Bundle \EasyAdminBundle \Field \AvatarField - 用于存储此值的 Doctrine DBAL 类型:
string
或text
- 用于渲染字段的 Symfony 表单类型: TextType
渲染为:
1
<input type="text">
选项
setHeight
头像图片被渲染为正方形,因此只有一个选项可以设置 height
,它将与其 width
相同。默认情况下,头像图片在 index
页面高度为 24px
,在 detail
页面高度为 48px
。使用此选项自定义此值
1 2 3 4 5 6 7 8 9 10
// if you pass an integer, it's considered the height in pixels
yield AvatarField::new('...')->setHeight(36);
// you can also use any of these predefined sizes:
// 'sm' = 18px; 'md' = 24px; 'lg' = 48px; 'xl' = 96px
yield AvatarField::new('...')->setHeight('lg');
// inside configureFields() you have access to the current page name
// use it to set different values per page
yield AvatarField::new('...')->setHeight($pageName === Crud::PAGE_DETAIL ? 'lg' : 21);
setIsGravatarEmail
默认情况下,EasyAdmin 认为存储在属性中的值是头像图片的完整 URL。如果您使用 Gravatar 服务,请设置此选项以告知 EasyAdmin 它必须使用存储在属性中的电子邮件动态生成头像图片 URL
1 2
// turns the email into an URL of the format: 'https://www.gravatar.com/avatar/...'
yield AvatarField::new('someEmail')->setIsGravatarEmail();
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。