diff --git a/core/modules/jsonld/jsonld.module b/core/modules/jsonld/jsonld.module index b9d75eb..a89b40f 100644 --- a/core/modules/jsonld/jsonld.module +++ b/core/modules/jsonld/jsonld.module @@ -4,3 +4,27 @@ * @file * Enables entity serialization in JSON-LD. */ + +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; + +/** + * Implements hook_route_info(). + * + * @todo Remove. + * Route handling will not be part of serialization modules under normal + * circumstances. This is here for testing. Once the REST module has set up + * routes, this can be removed. + */ +function jsonld_route_info() { + $collection = new RouteCollection(); + + $entity_test_route = new Route('entity/{entity_type}/{eid}', array( + '_controller' => '\Drupal\jsonld\JsonldController::entity_get', + ), array( + 'entity_type' => 'entity-test', + )); + $collection->add('entity_test_get_json_ld', $entity_test_route); + + return $collection; +} 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..3f49f8d --- /dev/null +++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldController.php @@ -0,0 +1,40 @@ +serialize($entity, 'drupal_jsonld'); + + $response = new Response($jsonld, 200, array('Content-type' => 'application/json')); + return $response; + } + +} diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 46def82..83906b7 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -18,6 +18,7 @@ function entity_test_entity_info() { ), 'base table' => 'entity_test', 'data table' => 'entity_test_property_data', + 'uri callback' => 'entity_test_uri', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'id', @@ -137,3 +138,9 @@ function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) { $langcode = $form_state['controller']->getFormLangcode($form_state); variable_set('entity_form_langcode', $langcode); } + +function entity_test_uri($entity_test) { + return array( + 'path' => 'entity_test/' . $entity_test->id(), + ); +}