forked from EasyCorp/EasyAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserCrudController.php
More file actions
84 lines (72 loc) · 2.58 KB
/
UserCrudController.php
File metadata and controls
84 lines (72 loc) · 2.58 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Controller;
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminAction;
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminCrud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\User;
use Symfony\Component\HttpFoundation\Response;
/**
* @extends AbstractCrudController<User>
*/
#[AdminCrud('/user-editor', 'external_user_editor')]
class UserCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return User::class;
}
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id')->hideOnForm(),
TextField::new('name'),
EmailField::new('email'),
];
}
public function configureFilters(Filters $filters): Filters
{
return $filters
->add('name')
->add('email');
}
#[AdminAction(routePath: '/custom/path-for-index', routeName: 'custom_route_for_index')]
public function index(AdminContext $context)
{
return parent::index($context);
}
#[AdminAction(routePath: '/custom/path-for-detail/{entityId}')]
public function detail(AdminContext $context)
{
return parent::detail($context);
}
#[AdminAction(routeName: 'custom_route_for_new')]
public function new(AdminContext $context)
{
return parent::new($context);
}
// this action doesn't use the #[AdminAction] attribute on purpose to test default behavior
public function edit(AdminContext $context)
{
return parent::edit($context);
}
#[AdminAction(routeName: 'foobar', routePath: '/bar/foo')]
public function someCustomAction(): Response
{
return new Response('This is a custom action');
}
#[AdminAction('/bar/bar', 'foofoo')]
public function anotherCustomActionWithoutPropertyNames(): Response
{
return new Response('This is custom action with short attribute syntax');
}
// this custom action doesn't use the #[AdminAction] attribute on purpose to test default behavior
public function anotherCustomAction(): Response
{
return new Response('This is another custom action');
}
}