| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class ShowImageType extends AbstractType{ |
||
| 13 | |||
| 14 | public function configureOptions(OptionsResolver $resolver) |
||
| 15 | { |
||
| 16 | // makes it legal for our field to have an image_property option |
||
| 17 | $resolver->setDefined(['image_property']); |
||
| 18 | } |
||
| 19 | |||
| 20 | public function buildView(FormView $view, FormInterface $form, array $options) |
||
| 21 | { |
||
| 22 | |||
| 23 | if(isset($options['image_property'])){ |
||
| 24 | |||
| 25 | // this will be whatever class/entity is bound to your form (e.g. Media) |
||
| 26 | $parentData = $form->getParent()->getData(); |
||
| 27 | |||
| 28 | $imageUrl = null; |
||
| 29 | |||
| 30 | if (null !== $parentData) { |
||
| 31 | $accessor = PropertyAccess::createPropertyAccessor(); |
||
| 32 | |||
| 33 | $imageUrl = $accessor->getValue($parentData, $options['image_property']); |
||
| 34 | |||
| 35 | } |
||
| 36 | |||
| 37 | // sets an "image_url" variable that will be available when rendering this field |
||
| 38 | $view->vars['image_url'] = $imageUrl; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | public function getParent(){ |
||
| 44 | } |
||
| 45 | } |