1 | <?php |
||
23 | class ContentItemTypeType extends AbstractType |
||
24 | { |
||
25 | /** |
||
26 | * Constructor |
||
27 | * |
||
28 | * @param \Sonata\AdminBundle\Admin\Pool $sonata |
||
29 | * @param string $contentItemClass |
||
30 | */ |
||
31 | public function __construct($contentItemClass, Pool $sonata = null) |
||
36 | |||
37 | |||
38 | /** |
||
39 | * @{inheritDoc} |
||
40 | */ |
||
41 | public function setDefaultOptions(OptionsResolverInterface $resolver) |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @{inheritDoc} |
||
56 | */ |
||
57 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
89 | |||
90 | |||
91 | /** |
||
92 | * @{inheritDoc} |
||
93 | */ |
||
94 | public function buildView(FormView $view, FormInterface $form, array $options) |
||
95 | { |
||
96 | if (isset($view->vars['sonata_admin']['admin'])) { |
||
97 | $genericAdmin = $view->vars['sonata_admin']['admin']; |
||
98 | |||
99 | $parentAdmin = $genericAdmin->getParent(); |
||
100 | |||
101 | $subject = $form->getParent()->getData(); |
||
102 | |||
103 | $view->vars['type'] = null; |
||
104 | $view->vars['edit_url'] = null; |
||
105 | |||
106 | |||
107 | try { |
||
108 | if ($subject->getRegion() !== null && $typeAdmin = $this->sonata->getAdminByClass(get_class($subject))) { |
||
109 | $view->vars['type']= Str::humanize(Str::classname($subject->getConvertToType())); |
||
110 | $childAdmin = $this->sonata->getAdminByAdminCode($parentAdmin->getCode() . '|' . $typeAdmin->getCode()); |
||
111 | $childAdmin->setRequest($genericAdmin->getRequest()); |
||
112 | |||
113 | if ($subject && $subject->getPage() && $subject->getPage()->getId()) { |
||
114 | try { |
||
115 | $view->vars['edit_url'] = $childAdmin->generateObjectUrl('edit', $subject); |
||
116 | } catch (InvalidParameterException $e) { |
||
117 | //2.2 edit url not needed when generating other admins (this is done in the POST of the sonata_collection_type) |
||
118 | } catch (MissingMandatoryParametersException $e) { |
||
119 | //>= 2.3 |
||
120 | } catch (\Exception $e) { |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | } catch (\RuntimeException $e) { |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Returns the name of this type. |
||
132 | * |
||
133 | * @return string The name of this type |
||
134 | */ |
||
135 | public function getName() |
||
139 | } |
||
140 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: