Detach given and create new keyword entity.

@param CategoryInterface $category
@param KeywordInterface $keyword

@return KeywordInterface
506822
private function handleDetach(KeywordInterface $keyword, CategoryInterface $category)
    {
        $keywordString = $keyword->getKeyword();
        $keywordLocale = $keyword->getLocale();

        // if keyword wont be deleted (because of multiple references)
        // refresh it to be sure hat changes wont be written to
        // database.
        $this->entityManager->refresh($keyword);

        // delete old keyword from category
        $this->delete($keyword, $category);

        // create new keyword
        $newEntity = $this->keywordRepository->createNew();
        $newEntity->setKeyword($keywordString);
        $newEntity->setLocale($keywordLocale);

        // add new keyword to category
        return $this->save($newEntity, $category);
    }
221949
public function removeCategory(\Enhavo\Bundle\CategoryBundle\Entity\Category $category)
    {
        $category->setCollection(null);
        $this->categories->removeElement($category);
    }
1088239
public function inCategory(string $category, string $domain = ''): self
    {
        $this->categories[] = ['category' => $category, 'domain'   => $domain];
        return $this;
    }
66749
public function removeCategories(Collection $categories)
    {
        foreach ($categories as $category) {
                $this->removeCategory($category);
        }

        return $this;
    }
585301
public function deleteCategory(Category $category)
    {
        $forum = $category->getForum();

        if ($this->authorization->isGranted('moderate', new ResourceCollection(array($category->getForum()->getResourceNode())))) {

            $this->manager->deleteCategory($category);

            return new RedirectResponse(
                $this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
            );
        }

        throw new AccessDeniedException();
    }
1070337
public function makeChildOf(CategoryInterface $category)
    {
        $this->save();
        $this->parents()->sync(array($category->getKey()));

        return $this;
    }
706588
protected function setCategory(CategoryInterface $category)
    {
        $this->category = $category;
        $this->attributeKeysAndControllers = null;
        $this->csvHeader = null;

        return $this;
    }
245799
public static function create_from_question_category_instance($category, $context = null) {

        $params = ['objectid' => $category->id];

        if (!empty($category->contextid)) {
            $params['contextid'] = $category->contextid;
        }

        $params['context'] = $context;

        $event = self::create($params);
        return $event;
    }
2444
public function getCategorySearchQuery(
        ContainerConfigurationInterface $containerConfigurationInterface,
        CategoryInterface $category
    ) {
        $filters = array_merge(
            ['category' => $this->categoryFilterProvider->getQueryFilter($category)],
            $containerConfigurationInterface->getFilters()
        );

        $filterQuery  = $this->queryBuilder->createFilterQuery($containerConfigurationInterface, $filters);

        return $this->queryFactory->create(QueryInterface::TYPE_FILTER, ['filter' => $filterQuery]);
    }
952458
public function create(CategoryCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $category = new CategoryModel();

        $category
            ->setDispatcher($dispatcher)

            ->setLocale($event->getLocale())
            ->setParent($event->getParent())
            ->setVisible($event->getVisible())
            ->setTitle($event->getTitle())

            ->save()
        ;

        $event->setCategory($category);
    }
1096284
public function destroy(CategoryGroup $categoryGroup, Category $category): JsonResponse
    {
        $categories = $categoryGroup->categories()->descendantsAndSelf(
            $category->id
        );

        foreach ($categories as $item) {
            $item->delete();
        };

        $this->clearCache();

        return response()->json([
            'state' => 'success',
        ]);
    }
1241549
public function add($category)
    {
        if (is_array($category)) {
            $this->collection[] = new Category($category);
        } elseif (is_object($category) && $category instanceof Category) {
            $this->collection[] = $category;
        }

        return $this;
    }
269394
public function addChild(CategoryInterface $child)
    {
        $child->setParent($this);
        $this->children[] = $child;

        return $this;
    }
494367
public function removeCategory(\Amulen\ClassificationBundle\Entity\Category $category)
    {
        $this->categories->removeElement($category);
    }
1056780
public static function createFromCategory(Category $category): self
    {
        $message = new self();
        $message->setId($category->getId());
        $message->setEnabled($category->isEnabled());

        foreach ($category->getTranslations() as $translation) {
            $transMessage = CategoryTranslationMessage::createFromCategoryTranslation($translation);

            $message->addTranslation($transMessage);
        }

        return $message;
    }
355900
public function postAction($categoryId, Request $request)
    {
        /** @var KeywordInterface $keyword */
        $keyword = $this->getKeywordRepository()->createNew();
        $category = $this->getCategoryRepository()->findCategoryById($categoryId);
        $keyword->setKeyword($request->get('keyword'));
        $keyword->setLocale($request->get('locale'));

        $keyword = $this->getKeywordManager()->save($keyword, $category);

        $this->getEntityManager()->persist($keyword);
        $this->getEntityManager()->flush();

        return $this->handleView($this->view($keyword));
    }
862538
public function moveSubjectAction(Subject $subject, Category $newCategory)
    {
        $forum = $newCategory->getForum();
        $this->checkAccess($forum);
        $this->manager->moveSubject($subject, $newCategory);

        return new RedirectResponse(
            $this->generateUrl('claro_forum_categories', array('forum' => $forum->getId()))
        );
    }