src/PHPDish/Bundle/ForumBundle/Form/DataTransformer/StringToThreadsTransformer.php
public function reverseTransform($value)
    {
        if (null === $value || '' === $value) {
            return null;
        }

        $threadNames = array_unique(array_filter(array_map('trim', explode(',', $value))));
        if (count($threadNames) === 0) {
            return null;
        }
        $threads =  $this->threadManager->findThreadsByNames($threadNames);
        $existingThreadNames = array_map(function(ThreadInterface $thread){
            return $thread->getName();
        }, $threads);

        //创建新的thread
        $nonExistThreads = $this->threadManager->createThreadsByNames(array_diff($threadNames, $existingThreadNames));
        return array_slice(array_merge($threads, $nonExistThreads), 0, 5); //只要五个
    }
public function reverseTransform($value)
    {
        if (null === $value || '' === $value) {
            return null;
        }

        $threadNames = array_unique(array_filter(array_map('trim', explode(',', $value))));
        if (count($threadNames) === 0) {
            return null;
        }
        $threads =  $this->threadManager->findThreadsByNames($threadNames);
        $existingThreadNames = array_map(function(ThreadInterface $thread){
            return $thread->getName();
        }, $threads);

        //创建新的thread
        $nonExistThreads = $this->threadManager->createThreadsByNames(array_diff($threadNames, $existingThreadNames));
        return array_slice(array_merge($threads, $nonExistThreads), 0, 5); //只要五个
    }
{@inheritdoc}