/**
  * Find or create group
  *
  * @param array $convertedItem
  *
  * @return GroupInterface
  */
 protected function findOrCreateGroup(array $convertedItem)
 {
     if (null === ($group = $this->findObject($this->repository, $convertedItem))) {
         $group = $this->groupFactory->createGroup($convertedItem['type']);
     }
     $isExistingGroup = null !== $group->getType() && true === $group->getType()->isVariant();
     if ($isExistingGroup) {
         $this->skipItemWithMessage($convertedItem, sprintf('Cannot process variant group "%s", only groups are accepted', $convertedItem['code']));
     }
     return $group;
 }
 /**
  * Create a group
  *
  * @param Request $request
  *
  * @Template
  * @AclAncestor("pim_enrich_group_create")
  *
  * @return Response|RedirectResponse
  */
 public function createAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return $this->redirectToRoute('pim_enrich_group_index');
     }
     $group = $this->groupFactory->createGroup();
     if ($this->groupHandler->process($group)) {
         $this->addFlash('success', 'flash.group.created');
         $url = $this->generateUrl('pim_enrich_group_edit', ['id' => $group->getId()]);
         $response = ['status' => 1, 'url' => $url];
         return new Response(json_encode($response));
     }
     return ['form' => $this->groupForm->createView()];
 }
 /**
  * {@inheritdoc}
  *
  * @Template
  * @AclAncestor("pim_enrich_variant_group_create")
  */
 public function createAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return new RedirectResponse($this->router->generate('pim_enrich_variant_group_index'));
     }
     $group = $this->groupFactory->createGroup('VARIANT');
     if ($this->groupHandler->process($group)) {
         $this->request->getSession()->getFlashBag()->add('success', new Message('flash.variant group.created'));
         $url = $this->router->generate('pim_enrich_variant_group_edit', ['id' => $group->getId()]);
         $response = ['status' => 1, 'url' => $url];
         return new Response(json_encode($response));
     }
     return ['form' => $this->groupForm->createView()];
 }