/** * Helps to render the category form for add/edit actions * @param Category $category * @param CategoryForm $form * @param $parentCategoryID * @return JsonModel */ protected function renderCategData(Category $category, CategoryForm $form, $parentCategoryID) { $action = $category->getId() ? 'edit' : 'add'; $categoryTree = $this->getServiceLocator()->get('category-tree'); $form->get('parent')->setValueOptions($categoryTree->getSelectOptions($category)); $form->get('parent')->setValue($parentCategoryID); $viewModel = new ViewModel(['action' => $action, 'id' => $category->getId(), 'form' => $form]); $viewModel->setTemplate('admin/category/edit'); $renderer = $this->getServiceLocator()->get('Zend\\View\\Renderer\\RendererInterface'); return new JsonModel(array('title' => $this->translator->translate(ucfirst($action) . ' a category'), 'form' => $renderer->render($viewModel), 'parent' => (int) $parentCategoryID)); }
/** * @param null $parentId * @param string $uniqueToken This should be changed with every successful insertion to prevent validator errors * @return array */ protected function preparePostAddData($parentId = null, $uniqueToken = 'a') { $form = new CategoryForm($this->entityManager); $postParams = ['parent' => $parentId, 'sort' => 0, 'category_csrf' => $form->get('category_csrf')->getValue()]; $allLangs = $this->entityManager->getRepository(get_class(new Lang()))->findAll(); foreach ($allLangs as $lang) { $postParams['content'][] = ['title' => 'Title in ' . $lang->getIsoCode() . $uniqueToken]; } return $postParams; }