Duplicate a content item

@param ContentInterface $content
197713
public function duplicate(ContentInterface $content)
    {
        //get valueset to clone
        $valueset = $content->getValueSet();

        //clone valueset
        $duplicatedValueset = clone $valueset;

        $this->detachAndPersist($duplicatedValueset);

        //duplicate content
        $duplicatedContent = clone $content;
        $duplicatedContent->setSlug(null);
        $duplicatedContent->setValueSet($duplicatedValueset);

        $this->detachAndPersist($duplicatedContent);

        //iterate values, clone each and assign duplicate valueset to it
        foreach ($valueset->getValues() as $value) {

            //skip empty attributes
            if (is_null($value->getId())) continue;

            $duplicatedValue = clone ($value);
            $duplicatedValue->setValueSet($duplicatedValueset);

            $this->detachAndPersist($duplicatedValue);
        }
        $this->em->flush();

        return $duplicatedContent->getId();
    }
1252468
public function setContent( $content ) {
		$this->original = $content;

		if ( $this->should_be_json( $content ) ) {
			$this->header( 'Content-Type', 'application/json' );

			$content = $this->prepare_json_content( $content );
		}

		parent::setContent( $content );

		return $this;
	}
1054682
protected function Prepare(&$Content) {
      
      foreach ($Content as &$ContentItem) {
         $ContentType = GetValue('ItemType', $ContentItem);
         
         $Replacement = array();
         $Fields = array('DiscussionID', 'CategoryID', 'DateInserted', 'DateUpdated', 'InsertUserID', 'Body', 'Format', 'ItemType');
         
         switch (strtolower($ContentType)) {
            case 'comment':
               $Fields = array_merge($Fields, array('CommentID'));
               
               // Comment specific
               $Replacement['Name'] = GetValueR('Discussion.Name', $ContentItem);
               break;
            
            case 'discussion':
               $Fields = array_merge($Fields, array('Name', 'Type'));
               break;
         }
         
         $Fields = array_fill_keys($Fields, TRUE);
         $Common = array_intersect_key($ContentItem, $Fields);
         $Replacement = array_merge($Replacement, $Common);
         $ContentItem = $Replacement;
         
         // Attach User
         $UserID = GetValue('InsertUserID', $ContentItem);
         $User = Gdn::UserModel()->GetID($UserID);
         $ContentItem['Author'] = $User;
      }
   }
195699
public function setContent($content)
    {
        $context = $this->_context;

        $context->content = (string)$content;

        return $this;
    }
169030
public function fill($content)
    {
        if ($this->hasInstructions($content)) {
            $instructions = $this->getInstructions();
            foreach ($instructions as $instruction) {
                $content = $this->parseInstructions($content, $instruction);
            }
        }
        return $this->fillContent($content);
    }
291329
public function duplicateAction($id)
    {
        $contentManager = $this->get('opifer.content.content_manager');
        $content        = $contentManager->getRepository()->find($id);

        if ( ! $content) {
            throw $this->createNotFoundException('No content found for id ' . $id);
        }

        $duplicateContentId = $contentManager->duplicate($content);

        return $this->redirect($this->generateUrl('opifer_content_content_edit', [
            'id' => $duplicateContentId,
        ]));
    }
207716
public function putContent($content)
    {
        // write to io stream
        $this->size = fwrite($this->inputStream, $content);
        // rewind file pointer
        rewind($this->inputStream);
    }
603963
protected function createEntityFromContent(string $content): EntityInterface
    {
        $result = $this->createEntity();
        $result->readData(new DataContainer($this->decodeContent($content)));
        return $result;
    }
1346747
public function appendContent($content)
    {
        if ($this->isVoid) {
            throw new Exception\RuntimeException(
                'Void elements can\'t contain content.'
            );
        }

        $this->content .= $content;

        return $this;
    }
1066040
public function duplicate(ContentTypeInterface $contentType)
    {
        $newContentType = clone $contentType;
        $newContentType->setDefaultListable($this->updateDefaultListable($newContentType->getDefaultListable()));

        foreach ($contentType->getFields() as $field) {
            $newField = clone $field;
            foreach ($field->getOptions() as $option) {
                $newOption = clone $option;
                $newField->addOption($newOption);
            }

            $newContentType->addFieldType($newField);
        }

        return $newContentType;
    }
1035058
public function duplicate(TemplateDuplicateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $source = TemplateQuery::create()->findPk($event->getSourceTemplateId())) {
            $source->setLocale($event->getLocale());
            
            $createEvent = new TemplateCreateEvent();
            $createEvent
                ->setLocale($event->getLocale())
                ->setTemplateName(
                    Translator::getInstance()->trans("Copy of %tpl", ["%tpl" => $source->getName() ])
                );
            
            $dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $createEvent);
            
            $clone = $createEvent->getTemplate();
            
            $attrList = AttributeTemplateQuery::create()->findByTemplateId($source->getId());
            
            /** @var  $feat AttributeTemplate */
            foreach ($attrList as $feat) {
                $dispatcher->dispatch(
                    TheliaEvents::TEMPLATE_ADD_ATTRIBUTE,
                    new TemplateAddAttributeEvent($clone, $feat->getAttributeId())
                );
            }
            
            $featList = FeatureTemplateQuery::create()->findByTemplateId($source->getId());
            
            /** @var  $feat FeatureTemplate */
            foreach ($featList as $feat) {
                $dispatcher->dispatch(
                    TheliaEvents::TEMPLATE_ADD_FEATURE,
                    new TemplateAddFeatureEvent($clone, $feat->getFeatureId())
                );
            }
            
            $event->setTemplate($clone);
        }
    }
937782
public function createExistingFieldsInNewVersion(Content $content)
    {
        foreach ($content->fields as $field) {
            $this->createExistingFieldInNewVersion($field, $content);
        }
    }
244484
public function setContent(Content $content)
    {
        $this->contentTypeName = $content->getType()->getName();
        $this->contentId = $content->getContentId();

        return parent::setContent($content);
    }
1252662
public function publishDraft( Content $content )
    {
        $this->getRepository()->sudo(
            function(Repository $repository) use ( $content )
            {
                $repository->getContentService()->publishVersion($content->versionInfo->id);
            }
        );
    }
1043383
public function setContent($content)
    {
        $this->contents = trim($content);

        $this->parsedContents = null;
        return $this;
    }
449441
public function setContent($content)
    {
        if (! $content) {
            return $this;
        }
        if (! is_array($content)) {
            $content = array( $content );
        }
        $this->clearContent();
        foreach ($content as $child) {
            $this->addChild($child);
        }

        return $this;
    }
108622
public function setContent($content)
    {
        $app = App::getInstance();

        $text = new \FelixOnline\Core\Text();
        $text->setContent($content);
        $text->save();

        $this->setText1($text);

        return $this;
    }