Completed
Pull Request — master (#596)
by
unknown
14:21
created

FormContractor::fixFieldDescription()   B

Complexity

Conditions 6
Paths 15

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 27
rs 8.439
cc 6
eloc 13
nc 15
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineORMAdminBundle\Builder;
13
14
use Sonata\AdminBundle\Admin\AdminInterface;
15
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
16
use Sonata\AdminBundle\Builder\AbstractFormContractor;
17
use Symfony\Component\Form\FormFactoryInterface;
18
19
class FormContractor extends AbstractFormContractor
20
{
21
    /**
22
     * @deprecated since version 3.0.4, to be removed in 4.0
23
     *
24
     * @var FormFactoryInterface
25
     */
26
    protected $fieldFactory;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
32
    {
33
        if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
34
            $metadata = $admin->getModelManager()->getMetadata($admin->getClass());
35
36
            // set the default field mapping
37
            if (isset($metadata->fieldMappings[$fieldDescription->getName()])) {
38
                $fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]);
39
            }
40
41
            // set the default association mapping
42
            if (isset($metadata->associationMappings[$fieldDescription->getName()])) {
43
                $fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]);
44
            }
45
        }
46
47
        if (!$fieldDescription->getType()) {
48
            throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
49
        }
50
51
        $fieldDescription->setAdmin($admin);
52
        $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard'));
53
54
        if ($fieldDescription->describesAssociation()) {
0 ignored issues
show
Bug introduced by
The method describesAssociation() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
            $admin->attachAdminClass($fieldDescription);
56
        }
57
    }
58
}
59