public function add()
 {
     $this->checkNonce();
     $noderef = $this->getNodeRef();
     $node = $noderef->generateNode();
     $this->NodeMapper->defaultsOnNode($node);
     $this->NodeBinder->bindPersistentFields($node, $this->getErrors(), $this->params, $this->rawParams);
     $this->NodeBinder->fireAddBindEvents($node, $this->getErrors(), $this->params, $this->rawParams);
     $this->getErrors()->throwOnError();
     $this->RegulatedNodeService->add($node);
     //$this->NodeMapper->populateNodeCheaters($node);
     $this->bindToActionDatasource(array($node));
     return new View($this->successView());
 }
 /**
  * Add a new file node and adds the associated file.
  *
  * @param Element|string $parentElement
  * @param string $newFile Full path to the new file
  * @param string $newFileName the new disired filename
  * @return Node
  */
 public function addFileNode($parentElement, $newFile, $newFileName)
 {
     // get the file element
     $element = $this->ElementService->oneFromAspect('@files');
     // get storage facility
     list($storageFacility, $sfParams) = $this->deriveStorageFacility($parentElement);
     // add the new file
     $newId = $storageFacility->findUniqueFileID($sfParams, $this->buildFilename($newFileName));
     $file = new StorageFacilityFile($newId, $newFile);
     $file = $storageFacility->putFile($sfParams, $file);
     //create the node
     $nodeRef = new NodeRef($element);
     $slug = SlugUtils::createSlug($newId);
     $nodeRef = $this->NodeService->generateUniqueNodeRef($nodeRef, $slug);
     $fileNode = $nodeRef->generateNode();
     // set the new id as title
     $fileNode->Title = $newId;
     // set permenant fields
     $fileNode->ActiveDate = $this->DateFactory->newStorageDate();
     $fileNode->Status = 'draft';
     // get metrics
     list($width, $height) = ImageUtils::getImageDimensions($newFile);
     // and mime-type
     $mimetype = FileSystemUtils::getMimetype($file->getExtension());
     // add the meta fields
     $fileNode->setMeta('#url', $file->getURL());
     $fileNode->setMeta('#mimetype', $mimetype);
     $fileNode->setMeta('#size', filesize($newFile));
     $fileNode->setMeta('#width', $width);
     $fileNode->setMeta('#height', $height);
     $fileNode->setMeta('#parent-element', $parentElement instanceof Element ? $parentElement->Slug : $parentElement);
     // do the add
     $this->RegulatedNodeService->add($fileNode);
     //add the node
     return $fileNode;
 }