getSaveCopyName() public static method

Returns a uniqe key for the element in the $target-Path (recursive)
public static getSaveCopyName ( string $type, string $sourceKey, Pimcore\Model\Element\ElementInterface $target ) : Pimcore\Model\Element\ElementInterface | string
$type string
$sourceKey string
$target Pimcore\Model\Element\ElementInterface
return Pimcore\Model\Element\ElementInterface | string
Ejemplo n.º 1
0
 /**
  * @param  AbstractObject $target
  * @param  AbstractObject $source
  * @return AbstractObject copied object
  */
 public function copyAsChild($target, $source)
 {
     //load properties
     $source->getProperties();
     //load all in case of lazy loading fields
     self::loadAllObjectFields($source);
     $new = clone $source;
     $new->o_id = null;
     $new->setChilds(null);
     $new->setKey(Element\Service::getSaveCopyName("object", $new->getKey(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setDao(null);
     $new->setLocked(false);
     $new->setCreationDate(time());
     $new->save();
     // $this->updateChilds($target, $new);
     return $new;
 }
Ejemplo n.º 2
0
 /**
  * @param  Asset $target
  * @param  Asset $source
  * @return Asset copied asset
  */
 public function copyAsChild($target, $source)
 {
     $source->getProperties();
     $new = clone $source;
     $new->id = null;
     if ($new instanceof Asset\Folder) {
         $new->setChilds(null);
     }
     $new->setFilename(Element\Service::getSaveCopyName("asset", $new->getFilename(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setDao(null);
     $new->setLocked(false);
     $new->setCreationDate(time());
     $new->setStream($source->getStream());
     $new->save();
     if ($target instanceof Asset\Folder) {
         $this->updateChilds($target, $new);
     }
     return $new;
 }
Ejemplo n.º 3
0
 /**
  * @param  Document $target
  * @param  Document $source
  * @return Document copied document
  */
 public function copyAsChild($target, $source, $enableInheritance = false)
 {
     if (method_exists($source, "getElements")) {
         $source->getElements();
     }
     $source->getProperties();
     $new = clone $source;
     $new->id = null;
     $new->setChilds(null);
     $new->setKey(Element\Service::getSaveCopyName("document", $new->getKey(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setResource(null);
     $new->setLocked(false);
     $new->setCreationDate(time());
     if (method_exists($new, "setPrettyUrl")) {
         $new->setPrettyUrl(null);
     }
     if ($enableInheritance && $new instanceof Document\PageSnippet) {
         $new->setElements(array());
         $new->setContentMasterDocumentId($source->getId());
     }
     $new->save();
     $this->updateChilds($target, $new);
     return $new;
 }
Ejemplo n.º 4
0
 /**
  * @param  AbstractObject $target
  * @param  AbstractObject $source
  * @return AbstractObject copied object
  */
 public function copyAsChild($target, $source)
 {
     //load properties
     $source->getProperties();
     //load all in case of lazy loading fields
     self::loadAllObjectFields($source);
     $new = clone $source;
     $new->o_id = null;
     $new->setChilds(null);
     $new->setKey(Element\Service::getSaveCopyName("object", $new->getKey(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setDao(null);
     $new->setLocked(false);
     $new->setCreationDate(time());
     $new->save();
     $this->updateChilds($target, $new);
     // triggers actions after the complete object cloning
     \Pimcore::getEventManager()->trigger('object.postCopy', $new, ['base_element' => $source]);
     return $new;
 }
Ejemplo n.º 5
0
 /**
  * @param  Asset $target
  * @param  Asset $source
  * @return Asset copied asset
  */
 public function copyAsChild($target, $source)
 {
     $source->getProperties();
     $new = clone $source;
     $new->id = null;
     if ($new instanceof Asset\Folder) {
         $new->setChilds(null);
     }
     $new->setFilename(Element\Service::getSaveCopyName("asset", $new->getFilename(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setDao(null);
     $new->setLocked(false);
     $new->setCreationDate(time());
     $new->setStream($source->getStream());
     $new->save();
     if ($target instanceof Asset\Folder) {
         $this->updateChilds($target, $new);
     }
     // triggers actions after the complete asset cloning
     \Pimcore::getEventManager()->trigger('asset.postCopy', $new, ['base_element' => $source]);
     return $new;
 }
Ejemplo n.º 6
0
 /**
  * @param $target
  * @param $source
  * @param bool $enableInheritance
  * @param bool $resetIndex
  * @return Document
  * @throws \Exception
  */
 public function copyAsChild($target, $source, $enableInheritance = false, $resetIndex = false)
 {
     if (method_exists($source, "getElements")) {
         $source->getElements();
     }
     $source->getProperties();
     $new = clone $source;
     $new->id = null;
     $new->setChilds(null);
     $new->setKey(Element\Service::getSaveCopyName("document", $new->getKey(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setDao(null);
     $new->setLocked(false);
     $new->setCreationDate(time());
     if ($resetIndex) {
         // this needs to be after $new->setParentId($target->getId()); -> dependency!
         $new->setIndex($new->getDao()->getNextIndex());
     }
     if (method_exists($new, "setPrettyUrl")) {
         $new->setPrettyUrl(null);
     }
     if ($enableInheritance && $new instanceof Document\PageSnippet) {
         $new->setElements([]);
         $new->setContentMasterDocumentId($source->getId());
     }
     $new->save();
     $this->updateChilds($target, $new);
     // triggers actions after the complete document cloning
     \Pimcore::getEventManager()->trigger('document.postCopy', $new, ['base_element' => $source]);
     return $new;
 }