/** * Renders the create category form. * * @param integer $categoryId * Category ID. * * @return Response */ public function formAction($categoryId) { $isNew = $categoryId === 'new'; $category = $isNew ? new Category() : $this->loadCategoryOrFail($categoryId); $files = $category->getFiles(); $file = null; if (is_array($files)) { foreach ($files as $categoryFile) { if ($categoryFile instanceof File) { $file = $categoryFile; } break; } } $data = $this->createTemplateData(); $data['action'] = $isNew ? 'Create' : 'Edit'; $data['category'] = $category; $data['filePath'] = $file ? $file->getPath() : ''; $data['displayTypeOptions'] = Category::getDisplayTypeOptions(); return $this->render('AppBundle:admin:categoryForm.html.twig', $data); }