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\DoctrinePHPCRAdminBundle\Builder; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
15
|
|
|
use Sonata\AdminBundle\Admin\FieldDescriptionInterface; |
16
|
|
|
use Sonata\AdminBundle\Builder\AbstractFormContractor; |
17
|
|
|
|
18
|
|
|
class FormContractor extends AbstractFormContractor |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The method defines the correct default settings for the provided FieldDescription. |
22
|
|
|
* |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
* |
25
|
|
|
* @throws \RuntimeException if the $fieldDescription does not specify a type. |
26
|
|
|
*/ |
27
|
|
|
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
28
|
|
|
{ |
29
|
|
|
$metadata = null; |
|
|
|
|
30
|
|
|
if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
31
|
|
|
/** @var \Doctrine\ODM\PHPCR\Mapping\ClassMetadata $metadata */ |
32
|
|
|
$metadata = $admin->getModelManager()->getMetadata($admin->getClass()); |
33
|
|
|
|
34
|
|
|
// set the default field mapping |
35
|
|
|
if (isset($metadata->mappings[$fieldDescription->getName()])) { |
36
|
|
|
$fieldDescription->setFieldMapping($metadata->mappings[$fieldDescription->getName()]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// set the default association mapping |
40
|
|
|
if ($metadata->hasAssociation($fieldDescription->getName())) { |
41
|
|
|
$fieldDescription->setAssociationMapping($metadata->getAssociation($fieldDescription->getName())); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (!$fieldDescription->getType()) { |
46
|
|
|
throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$fieldDescription->setAdmin($admin); |
50
|
|
|
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard')); |
51
|
|
|
|
52
|
|
|
if ($fieldDescription->describesAssociation()) { |
|
|
|
|
53
|
|
|
$admin->attachAdminClass($fieldDescription); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
61
|
|
|
{ |
62
|
|
|
$options = parent::getDefaultOptions($type, $fieldDescription); |
63
|
|
|
|
64
|
|
|
switch ($type) { |
65
|
|
|
case 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType': |
66
|
|
|
case 'doctrine_phpcr_odm_tree': |
67
|
|
|
$options['class'] = $fieldDescription->getTargetEntity(); |
68
|
|
|
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
69
|
|
|
break; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $options; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.