1 | <?php |
||
22 | class ShowBuilder implements ShowBuilderInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var TypeGuesserInterface |
||
26 | */ |
||
27 | protected $guesser; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $templates; |
||
33 | |||
34 | /** |
||
35 | * @param TypeGuesserInterface $guesser |
||
36 | * @param array $templates Indexed by field type |
||
37 | */ |
||
38 | public function __construct(TypeGuesserInterface $guesser, array $templates) |
||
43 | |||
44 | /** |
||
45 | * {@inheritDoc} |
||
46 | */ |
||
47 | public function getBaseList(array $options = array()) |
||
48 | { |
||
49 | return new FieldDescriptionCollection(); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin) |
||
56 | { |
||
57 | if ($type == null) { |
||
58 | $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager()); |
||
59 | $fieldDescription->setType($guessType->getType()); |
||
60 | } else { |
||
61 | $fieldDescription->setType($type); |
||
62 | } |
||
63 | |||
64 | $this->fixFieldDescription($admin, $fieldDescription); |
||
65 | $admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription); |
||
66 | |||
67 | $list->add($fieldDescription); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param string $type |
||
72 | * |
||
73 | * @return string|null The template if found |
||
74 | */ |
||
75 | private function getTemplate($type) |
||
83 | |||
84 | /** |
||
85 | * The method defines the correct default settings for the provided FieldDescription |
||
86 | * |
||
87 | * {@inheritDoc} |
||
88 | * |
||
89 | * @throws \RuntimeException if the $fieldDescription does not have a type. |
||
90 | */ |
||
91 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
136 | } |
||
137 |