/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $nodeTranslation = $form->getParent()->getData(); $view->vars['reset'] = $this->slugifier->slugify($nodeTranslation->getTitle(), ''); $parentNode = $nodeTranslation->getNode()->getParent(); if ($parentNode !== null) { $nodeTranslation = $parentNode->getNodeTranslation($nodeTranslation->getLang(), true); $slug = $nodeTranslation->getSlugPart(); if (!empty($slug)) { $slug .= '/'; } $view->vars['prefix'] = $slug; } }
/** * * * @param Media $media * @return string */ private function getFilePath(Media $media) { $filename = $media->getOriginalFilename(); $filename = str_replace(array('/', '\\', '%'), '', $filename); $slugifier = new Slugifier(); if (!empty($this->blacklistedExtensions)) { $filename = preg_replace('/\\.(' . join('|', $this->blacklistedExtensions) . ')$/', '.txt', $filename); } $parts = pathinfo($filename); $filename = $slugifier->slugify($parts['filename']); $filename .= '.' . strtolower($parts['extension']); return sprintf('%s/%s', $media->getUuid(), $filename); }