forked from EasyCorp/EasyAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormFieldValueController.php
More file actions
31 lines (27 loc) · 1.18 KB
/
FormFieldValueController.php
File metadata and controls
31 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;
/**
* @extends AbstractCrudController<BlogPost>
*/
class FormFieldValueController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return BlogPost::class;
}
public function configureFields(string $pageName): iterable
{
// these fields format the original value with some options (e.g. max length)
// and then use the formatValue() method to test that this method receives the
// original field value, not the one modified with the other options
return [
TextField::new('title')->setMaxLength(2)->formatValue(fn ($value, $entity) => $value),
DateTimeField::new('createdAt')->setFormat('long', 'long')
->formatValue(fn (/** @var \DateTimeInterface $value */ $value, $entity) => date('YmdHis', $value->getTimestamp())),
];
}
}