/**
  * Find or create the category
  *
  * @param array $convertedItem
  *
  * @return CategoryInterface
  */
 protected function findOrCreateCategory(array $convertedItem)
 {
     $category = $this->findObject($this->repository, $convertedItem);
     if (null === $category) {
         $category = $this->categoryFactory->create();
     }
     return $category;
 }
 /**
  * Create a tree or category
  *
  * @param Request $request
  * @param int     $parent
  *
  * @throws AccessDeniedException
  *
  * @return Response|RedirectResponse
  */
 public function createAction(Request $request, $parent = null)
 {
     if (false === $this->securityFacade->isGranted($this->buildAclName('category_create'))) {
         throw new AccessDeniedException();
     }
     $category = $this->categoryFactory->create();
     if ($parent) {
         $parent = $this->findCategory($parent);
         $category->setParent($parent);
     }
     $category->setCode($request->get('label'));
     $this->eventDispatcher->dispatch(CategoryEvents::PRE_CREATE, new GenericEvent($category));
     $form = $this->createForm($this->rawConfiguration['form_type'], $category, $this->getFormOptions($category));
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $this->categorySaver->save($category);
             $message = new Message(sprintf('flash.%s.created', $category->getParent() ? 'category' : 'tree'));
             $this->addFlash('success', $message);
             $this->eventDispatcher->dispatch(CategoryEvents::POST_CREATE, new GenericEvent($category));
             return $this->redirectToRoute($this->buildRouteName('categorytree_edit'), ['id' => $category->getId()]);
         }
     }
     return $this->render(sprintf('PimEnrichBundle:CategoryTree:%s.html.twig', $request->get('content', 'edit')), ['form' => $form->createView(), 'related_entity' => $this->rawConfiguration['related_entity'], 'acl' => $this->rawConfiguration['acl'], 'route' => $this->rawConfiguration['route']]);
 }
 /**
  * Get a new tree instance
  *
  * @return CategoryInterface
  *
  * @deprecated Please use CategoryFactory::create() instead
  */
 public function getTreeInstance()
 {
     return $this->categoryFactory->create();
 }