private function setTaxonomyCollection(Entity\Content $contentEntity, $contentType)
    {
        if (empty($contentType['taxonomy'])) {
            return;
        }
        /** @var Collection\Taxonomy $taxonomies */
        $taxonomies = $this->repository->getEntityManager()->createCollection(Entity\Taxonomy::class);

        foreach ($contentType['taxonomy'] as $key => $taxonomy) {
            $taxEntity = null;

            if (isset($this->taxConfig[$taxonomy]['options'])) {
                $options = $this->taxConfig[$taxonomy]['options'];
                $key = array_rand($options);

                $taxEntity = $this->getTaxonomyEntity($contentEntity, $taxonomy);
                $taxEntity->setSlug($key);
                $taxEntity->setName($options[$key]);
                $taxEntity->setSortorder(rand(1, 1000));

                $taxonomies->add($taxEntity);
            }

            if ($this->taxConfig[$taxonomy]['behaves_like'] === 'tags') {
                $tags = $this->getRandomTags(5);
                foreach ($tags as $tag) {
                    $taxEntity = $this->getTaxonomyEntity($contentEntity, $taxonomy);
                    $taxEntity->setSlug($tag);
                    $taxEntity->setName($tag);

                    $taxonomies->add($taxEntity);
                }
            }
        }

        $contentEntity->setTaxonomy($taxonomies);
    }
private function setTaxonomyCollection(Entity\Content $contentEntity, $contentType)
    {
        if (empty($contentType['taxonomy'])) {
            return;
        }
        /** @var Collection\Taxonomy $taxonomies */
        $taxonomies = $this->repository->getEntityManager()->createCollection(Entity\Taxonomy::class);

        foreach ($contentType['taxonomy'] as $key => $taxonomy) {
            $taxEntity = null;

            if (isset($this->taxConfig[$taxonomy]['options'])) {
                $options = $this->taxConfig[$taxonomy]['options'];
                $key = array_rand($options);

                $taxEntity = $this->getTaxonomyEntity($contentEntity, $taxonomy);
                $taxEntity->setSlug($key);
                $taxEntity->setName($options[$key]);
                $taxEntity->setSortorder(rand(1, 1000));

                $taxonomies->add($taxEntity);
            }

            if ($this->taxConfig[$taxonomy]['behaves_like'] === 'tags') {
                $tags = $this->getRandomTags(5);
                foreach ($tags as $tag) {
                    $taxEntity = $this->getTaxonomyEntity($contentEntity, $taxonomy);
                    $taxEntity->setSlug($tag);
                    $taxEntity->setName($tag);

                    $taxonomies->add($taxEntity);
                }
            }
        }

        $contentEntity->setTaxonomy($taxonomies);
    }
private function setTaxonomyCollection ( Entity \ Content $ contentEntity , $ contentType ) { if ( empty ( $ contentType [ 'taxonomy' ] ) ) { return ; } /** @var Collection\Taxonomy $taxonomies */ $ taxonomies = $ this -> repository -> getEntityManager ( ) -> createCollection ( Entity \ Taxonomy :: class ) ; foreach ( $ contentType [ 'taxonomy' ] as $ key => $ taxonomy ) { $ taxEntity = null ; if ( isset ( $ this -> taxConfig [ $ taxonomy ] [ 'options' ] ) ) { $ options = $ this -> taxConfig [ $ taxonomy ] [ 'options' ] ; $ key = array_rand ( $ options ) ; $ taxEntity = $ this -> getTaxonomyEntity ( $ contentEntity , $ taxonomy ) ; $ taxEntity -> setSlug ( $ key ) ; $ taxEntity -> setName ( $ options [ $ key ] ) ; $ taxEntity -> setSortorder ( rand ( 1 , 1000 ) ) ; $ taxonomies -> add ( $ taxEntity ) ; } if ( $ this -> taxConfig [ $ taxonomy ] [ 'behaves_like' ] === 'tags' ) { $ tags = $ this -> getRandomTags ( 5 ) ; foreach ( $ tags as $ tag ) { $ taxEntity = $ this -> getTaxonomyEntity ( $ contentEntity , $ taxonomy ) ; $ taxEntity -> setSlug ( $ tag ) ; $ taxEntity -> setName ( $ tag ) ; $ taxonomies -> add ( $ taxEntity ) ; } } } $ contentEntity -> setTaxonomy ( $ taxonomies ) ; }
Add some random taxonomy entries on the record.

@param Entity\Content    $contentEntity
@param array|ContentType $contentType
Add some random taxonomy entries on the record .