Passed
Push — master ( 955e4f...05df7e )
by Jeff
02:10
created

AliasCrudController::configureFields()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 20
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Controller\Admin;
12
13
use App\Entity\Alias;
14
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
15
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
16
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
17
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
18
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
19
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
20
21
class AliasCrudController extends AbstractCrudController
22
{
23
    public static function getEntityFqcn(): string
24
    {
25
        return Alias::class;
26
    }
27
28
    public function configureCrud(Crud $crud): Crud
29
    {
30
        return $crud
31
            ->setEntityLabelInSingular('Alias')
32
            ->setEntityLabelInPlural('Alias')
33
            ->setSearchFields(['id', 'name', 'destination']);
34
    }
35
36
    public function configureFields(string $pageName): iterable
37
    {
38
        $domain = AssociationField::new('domain');
39
        $name = TextField::new('name');
40
        $destination = EmailField::new('destination');
41
        $id = IdField::new('id', 'ID');
42
43
        if (Crud::PAGE_DETAIL === $pageName) {
44
            return [$id, $name, $destination, $domain];
45
        }
46
47
        if (Crud::PAGE_NEW === $pageName) {
48
            return [$domain, $name, $destination];
49
        }
50
51
        if (Crud::PAGE_EDIT === $pageName) {
52
            return [$domain, $name, $destination];
53
        }
54
55
        return [$domain, $name, $destination];
56
    }
57
}
58