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

DomainCrudController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureCrud() 0 3 1
A getEntityFqcn() 0 3 1
A configureFields() 0 23 4
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\Domain;
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\BooleanField;
18
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
19
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
20
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
21
22
class DomainCrudController extends AbstractCrudController
23
{
24
    public static function getEntityFqcn(): string
25
    {
26
        return Domain::class;
27
    }
28
29
    public function configureCrud(Crud $crud): Crud
30
    {
31
        return $crud->setSearchFields(['name']);
32
    }
33
34
    public function configureFields(string $pageName): iterable
35
    {
36
        $name = TextField::new('name');
37
        $id = IdField::new('id', 'ID');
38
        $dkimEnabled = BooleanField::new('dkimEnabled');
39
        $dkimSelector = TextField::new('dkimSelector');
40
        $dkimPrivateKey = TextareaField::new('dkimPrivateKey');
41
        $users = AssociationField::new('users');
42
        $aliases = AssociationField::new('aliases');
43
44
        if (Crud::PAGE_DETAIL === $pageName) {
45
            return [$id, $name, $dkimEnabled, $dkimSelector, $dkimPrivateKey, $users, $aliases];
46
        }
47
48
        if (Crud::PAGE_NEW === $pageName) {
49
            return [$name];
50
        }
51
52
        if (Crud::PAGE_EDIT === $pageName) {
53
            return [$name];
54
        }
55
56
        return [$name, $aliases, $users];
57
    }
58
}
59