/** * Never call this method directly, but use createWithParent on your CollectionDefinition * to get a collection tied to concrete data. * * @private * * @param EntityInterface $parent */ public function loadFromParent(EntityInterface $parent) { $this->_children = array(); $object = $parent->getObject(); $parentMapper = $parent->getMapper(); $children = $parentMapper->getChildren($object, $this); // create entities for children foreach ($children as $child) { if (count($this->_typenames) === 1) { $type = $this->_typeFactory->getTypeByRdf(current($this->_typenames)); } else { $type = $this->_typeFactory->getTypeByObject($child); } foreach ($type->getVocabularies() as $prefix => $uri) { $this->setAttribute('xmlns:' . $prefix, $uri); } $this->_children[] = $type->createWithObject($child); } if ($this->_parent->isEditable($object) && sizeof($this->_children) == 0 && count($this->_typenames) == 1) { // create an empty element to allow adding new elements to an empty editable collection $type = $this->_typeFactory->getTypeByRdf(reset($this->_typenames)); $mapper = $type->getMapper(); $object = $mapper->prepareObject($type, $object); $entity = $type->createWithObject($object); if ($entity instanceof NodeInterface) { /** @var $entity NodeInterface */ $entity->setAttribute('style', 'display:none'); } $this->_children[] = $entity; } }
/** * Handle document POST (creation) * * @param Request $request * * @return Response * * @throws AccessDeniedException If the action is not allowed by the access * checker. */ public function postDocumentAction(Request $request) { if (!$this->accessChecker->check($request)) { throw new AccessDeniedException(); } $rdfType = trim($request->request->get('@type'), '<>'); $type = $this->typeFactory->getTypeByRdf($rdfType); $result = $this->restHandler->run($request->request->all(), $type, null, RestService::HTTP_POST); if (!is_null($result)) { $view = View::create($result)->setFormat('json'); return $this->viewHandler->handle($view, $request); } return Response::create('The document was not created', 500); }