|
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()) { |
|
55
|
|
|
$admin->attachAdminClass($fieldDescription); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|