Ejemplo n.º 1
0
 /**
  * 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;
     }
 }
Ejemplo n.º 2
0
 /**
  * Handle arbitrary methods with the RestHandler.
  *
  * Except for the PUT operation to update a document, operations are
  * registered as workflows.
  *
  * @param Request $request
  * @param string  $subject URL of the subject, ie: /cms/simple/news/news-name
  *
  * @return Response
  *
  * @throws AccessDeniedException If the action is not allowed by the access
  *                               checker.
  *
  * @see RestService::run
  *
  * @since 1.2
  */
 public function updateDocumentAction(Request $request, $subject)
 {
     if (!$this->accessChecker->check($request)) {
         throw new AccessDeniedException();
     }
     $model = $this->getModelBySubject($request, $subject);
     $type = $this->typeFactory->getTypeByObject($model);
     $result = $this->restHandler->run($request->request->all(), $type, $subject, strtolower($request->getMethod()));
     $view = View::create($result)->setFormat('json');
     return $this->viewHandler->handle($view, $request);
 }