src/Sulu/Bundle/CategoryBundle/Api/Category.php
public function setTranslation(CategoryTranslationInterface $translation)
    {
        $translationEntity = $this->getTranslationByLocale($translation->getLocale());

        if (!$translationEntity) {
            $translationEntity = $translation;
            $this->entity->addTranslation($translationEntity);
        }

        $translationEntity->setCategory($this->entity);
        $translationEntity->setTranslation($translation->getTranslation());
        $translationEntity->setLocale($translation->getLocale());

        if (null === $this->getId() && null === $this->getDefaultLocale()) {
            // new entity and new translation
            // save first locale as default
            $this->entity->setDefaultLocale($translationEntity->getLocale());
        }
    }
public function setTranslation(CategoryTranslationInterface $translation)
    {
        $translationEntity = $this->getTranslationByLocale($translation->getLocale());

        if (!$translationEntity) {
            $translationEntity = $translation;
            $this->entity->addTranslation($translationEntity);
        }

        $translationEntity->setCategory($this->entity);
        $translationEntity->setTranslation($translation->getTranslation());
        $translationEntity->setLocale($translation->getLocale());

        if (null === $this->getId() && null === $this->getDefaultLocale()) {
            // new entity and new translation
            // save first locale as default
            $this->entity->setDefaultLocale($translationEntity->getLocale());
        }
    }
public function setTranslation ( CategoryTranslationInterface $ translation ) { $ translationEntity = $ this -> getTranslationByLocale ( $ translation -> getLocale ( ) ) ; if ( ! $ translationEntity ) { $ translationEntity = $ translation ; $ this -> entity -> addTranslation ( $ translationEntity ) ; } $ translationEntity -> setCategory ( $ this -> entity ) ; $ translationEntity -> setTranslation ( $ translation -> getTranslation ( ) ) ; $ translationEntity -> setLocale ( $ translation -> getLocale ( ) ) ; if ( null === $ this -> getId ( ) && null === $ this -> getDefaultLocale ( ) ) { // new entity and new translation // save first locale as default $ this -> entity -> setDefaultLocale ( $ translationEntity -> getLocale ( ) ) ; } }
Sets a translation to the entity.
If no other translation was assigned before, the translation is added as default.

@param CategoryTranslationInterface $translation
Sets a translation to the entity . If no other translation was assigned before the translation is added as default .