/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); $view->vars['filter'] = $options['filter']; $view->vars['object'] = $form->getParent()->getData(); $view->vars['preview'] = $options['preview']; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); $data = $form->getData(); if (is_string($data)) { $data = ['filename' => basename($data), 'url' => $data]; } if (is_array($data)) { if (!isset($view->var['url']) && isset($data['url'])) { $view->vars['url'] = $data['url']; } if (!isset($view->var['filename']) && isset($data['filename'])) { $view->vars['filename'] = $data['filename']; } } // autodetect type of upload $uploadtype = $options['uploadtype']; if (isset($view->vars['filename'])) { $file = new File($view->vars['filename'], false); $view->vars['filetype'] = $file->getExtension(); switch ($file->getExtension()) { case 'png': case 'jpg': case 'jpeg': case 'gif': $uploadtype = 'image'; break; case 'mp4': $uploadtype = 'video'; break; case 'mp3': case 'm4v': $uploadtype = 'audio'; break; default: break; } } $view->vars['uploadtype'] = $uploadtype; $view->vars['placeholdWidth'] = $options['placeholdWidth']; $view->vars['placeholdHeight'] = $options['placeholdHeight']; $view->vars['placeholdText'] = $options['placeholdText']; $view->vars['ratio'] = $options['ratio']; $view->vars['remove'] = $options['remove']; $pattern = $options['pattern']; if ($pattern != null) { if (!$this->container->hasParameter($pattern)) { throw new \Exception('You must define an existing pattern'); } $patternSize = $this->container->getParameter($pattern); $view->vars['label'] .= ' (Max width: ' . $patternSize['width'] . ', Max height: ' . $patternSize['height'] . ')'; } }
public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); $view->vars = array_replace($view->vars, array('type' => 'file', 'value' => '')); if (array_key_exists('file_path', $options)) { $parentData = $form->getParent()->getData(); if (null !== $parentData) { $accessor = PropertyAccess::getPropertyAccessor(); $imageUrl = $accessor->getValue($parentData, $options['file_path']); $value = $accessor->getValue($parentData, 'filePath'); } else { $imageUrl = null; $value = null; } // set an "image_url" variable that will be available when rendering this field $view->vars['file_url'] = $imageUrl; $view->vars['value'] = $value; } }
public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); $view->vars = array_replace($view->vars, array('type' => 'file', 'value' => '')); if (array_key_exists('file_path', $options)) { $parentData = $form->getParent()->getData(); if (!is_null($parentData)) { $accessor = PropertyAccess::getPropertyAccessor(); $imageUrl = $accessor->getValue($parentData, $options['file_path']); $value = $accessor->getValue($parentData, 'filePath'); } else { $imageUrl = null; $value = null; } $view->vars['file_url'] = $imageUrl; $view->vars['value'] = $value; } $view->vars['file_path'] = $options['show_path']; }
public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); $view->vars['image'] = $options['image']; }