diff --git a/core/modules/jsonld/jsonld.info b/core/modules/jsonld/jsonld.info index 110b881..69414e6 100644 --- a/core/modules/jsonld/jsonld.info +++ b/core/modules/jsonld/jsonld.info @@ -3,3 +3,4 @@ description = Serializes entities using JSON-LD format. package = Core core = 8.x dependencies[] = rdf +dependencies[] = entity_test \ No newline at end of file diff --git a/core/modules/jsonld/jsonld.routing.yml b/core/modules/jsonld/jsonld.routing.yml new file mode 100644 index 0000000..9f1daed --- /dev/null +++ b/core/modules/jsonld/jsonld.routing.yml @@ -0,0 +1,9 @@ +entity_test_get_json_ld: + pattern: 'entity/{entity_type}/{eid}' + defaults: + _controller: '\Drupal\jsonld\JsonldController::entity_get' + +entity_test_post_json_ld: + pattern: 'entity/post' + defaults: + _controller: '\Drupal\jsonld\JsonldController::entity_post' \ No newline at end of file diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldController.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldController.php new file mode 100644 index 0000000..0d448a6 --- /dev/null +++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldController.php @@ -0,0 +1,54 @@ +get('serializer'); + + $jsonld = $serializer->serialize($entity, 'drupal_jsonld'); + + $response = new Response($jsonld, 200, array('Content-type' => 'application/json')); + return $response; + } + + public function entity_post() { + $container = drupal_container(); + $kernel = $container->get('http_kernel'); + $request = $container->get('request'); + $subRequest = Request::create('http://d8.l/entity/entity-test/1', 'get', array(), $request->cookies->all(), array(), $request->server->all()); + $jsonld = $kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); + + $serializer = drupal_container()->get('serializer'); + $entity = $serializer->deserialize($jsonld->getContent(), '\Drupal\Core\Entity\EntityNG', 'drupal_jsonld'); + + $foo = $entity->get('user_id')->get('entity'); + $entity->save(); + return $response; + } + +}