diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php index cfffa8c..8acb212 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php @@ -78,7 +78,7 @@ public function getId() { public function getTypeUri() { $entity_type = $this->entity->entityType(); $bundle = $this->entity->bundle(); - return url('site-schema/content-staging/' . $entity_type . '/' . $bundle, array('absolute' => TRUE)); + return url('site-schema/content-deployment/' . $entity_type . '/' . $bundle, array('absolute' => TRUE)); } /** diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php index 9ecfda5..e4b1636 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php @@ -147,7 +147,7 @@ public function testNormalize() { function testDenormalize() { $incomingData = array( - '@type' => url('jsonld-test/content-staging/entity_test/entity_test', array('absolute' => TRUE)), + '@type' => url('jsonld-test/content-deployment/entity_test/entity_test', array('absolute' => TRUE)), 'name' => array( 'en' => array( array( diff --git a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php new file mode 100644 index 0000000..f05d12b --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php @@ -0,0 +1,64 @@ +getRouteCollection(); + + // The paths of the site-generated schemas. + $schemaPaths = array( + SiteSchema::CONTENT_DEPLOYMENT, + SiteSchema::SYNDICATION, + ); + + // Add the routes for all of the terms in both schemas. + foreach ($schemaPaths as $schemaPath) { + $schema = new SiteSchema($schemaPath); + $routes = $schema->getRoutes(); + foreach ($routes as $controller => $pattern) { + $route = new Route($pattern, array( + '_controller' => 'Drupal\rdf\SiteSchema\SchemaController::' . $controller, + 'schema_path' => $schemaPath, + ), array( + '_method' => 'GET', + )); + // Create the route name to use in the RouteCollection. Remove the + // trailing slash and replace characters, so that a path such as + // site-schema/syndication/ becomes rdf.site_schema.syndication. + $routeName = 'rdf.' . str_replace(array('-','/'), array('_', '.'), substr_replace($schemaPath ,"",-1)); + $collection->add($routeName, $route); + } + } + } + + /** + * Implements EventSubscriberInterface::getSubscribedEvents(). + */ + static function getSubscribedEvents() { + $events[RoutingEvents::DYNAMIC] = 'routes'; + return $events; + } +} + diff --git a/core/modules/rdf/lib/Drupal/rdf/RdfBundle.php b/core/modules/rdf/lib/Drupal/rdf/RdfBundle.php new file mode 100644 index 0000000..cd95af9 --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/RdfBundle.php @@ -0,0 +1,26 @@ +register('rdf.route_subscriber', 'Drupal\rdf\EventSubscriber\RouteSubscriber') + ->addTag('event_subscriber'); + } +} diff --git a/core/modules/rdf/lib/Drupal/rdf/RdfConstants.php b/core/modules/rdf/lib/Drupal/rdf/RdfConstants.php new file mode 100644 index 0000000..f970e44 --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/RdfConstants.php @@ -0,0 +1,26 @@ +bundle = $bundle; + } + + /** + * Implements \Drupal\rdf\SiteSchema\SchemaBase::getUri(). + */ + public function getUri() { + $path = str_replace(array('{entity_type}', '{bundle}'), array($this->entityType, $this->bundle), self::URI_PATTERN); + return $this->siteSchema->getUri() . $path; + } + + /** + * Overrides \Drupal\rdf\SiteSchema\SchemaBase::getProperties(). + */ + public function getProperties() { + $properties = parent::getProperties(); + $properties[RdfConstants::RDFS_SUB_CLASS_OF] = $this->siteSchema->entity($this->entityType)->getUri(); + return $properties; + } + +} diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php new file mode 100644 index 0000000..362494e --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php @@ -0,0 +1,57 @@ +entityType = $entity_type; + } + + /** + * Implements \Drupal\rdf\SiteSchema\SchemaBase::getUri(). + */ + public function getUri() { + $path = str_replace('{entity_type}', $this->entityType , self::URI_PATTERN); + return $this->siteSchema->getUri() . $path; + } + + /** + * Overrides \Drupal\rdf\SiteSchema\SchemaBase::getProperties(). + */ + public function getProperties() { + $properties = parent::getProperties(); + $properties[RdfConstants::RDF_TYPE] = RdfConstants::RDFS_CLASS; + return $properties; + } + +} diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaBase.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaBase.php new file mode 100644 index 0000000..429788b --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaBase.php @@ -0,0 +1,57 @@ +siteSchema = $siteSchema; + } + + /** + * Get the term properties. + * + * @return array + * An array of properties for this term, keyed by URI. + */ + public function getProperties() { + return array( + RdfConstants::RDFS_IS_DEFINED_BY => $this->siteSchema->getUri(), + ); + } + + /** + * Get the URI of the term. + * + * Implementations of this method will use the URI patterns defined in + * URI_PATTERN constants and replace placeholders with actual values. + * + * @return string + * The URI of the term. + */ + abstract public function getUri(); + +} diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php new file mode 100644 index 0000000..9a60bc6 --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php @@ -0,0 +1,49 @@ + $entity_type))); + } + if (!array_key_exists($bundle, $entity_info['bundles'])) { + throw new NotFoundHttpException(t('Bundle @bundle not found', array('@bundle' => $bundle))); + } + + $serializer = drupal_container()->get('serializer'); + $siteSchema = new SiteSchema($schema_path); + // @todo Remove hard-coded mimetype once we have proper conneg. + $content = $serializer->serialize($siteSchema->bundle($entity_type, $bundle), 'jsonld'); + return new Response($content, 200, array('Content-type' => 'application/json')); + } + +} diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php new file mode 100644 index 0000000..ec15225 --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php @@ -0,0 +1,73 @@ +schemaPath = $schemaPath; + } + + /** + * Get an entity's term definition in this vocabulary. + */ + public function entity($entity_type) { + return new EntitySchema($this, $entity_type); + } + + /** + * Get a bundle's term definition in this vocabulary. + */ + public function bundle($entity_type, $bundle) { + return new BundleSchema($this, $entity_type, $bundle); + } + + /** + * Get the URI of the schema. + * + * @return string + * The URI of the schema. + */ + public function getUri() { + return url($this->schemaPath, array('absolute' => TRUE)); + } + + /** + * Get the routes for the types of terms defined in this schema. + * + * @return array + * An array of route patterns, keyed by controller method name. + */ + public function getRoutes() { + return array( + 'bundle' => $this->schemaPath . BundleSchema::URI_PATTERN, + ); + } +} diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/SiteSchemaTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/SiteSchemaTest.php new file mode 100644 index 0000000..f0e55f0 --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/SiteSchemaTest.php @@ -0,0 +1,55 @@ + 'RDF site schema test', + 'description' => 'Confirm that site-generated schemas are created for entity, bundle, field, and field property.', + 'group' => 'RDF', + ); + } + + /** + * Tests site-generated schema. + */ + function testSiteSchema() { + $entityType = $bundle = 'entity_test'; + $schema = new SiteSchema(SiteSchema::SYNDICATION); + $schemaPath = 'site-schema/syndication/'; + + // Bundle. + $bundleSchema = $schema->bundle($entityType, $bundle); + $bundleUri = url("$schemaPath$entityType/$bundle", array('absolute' => TRUE)); + $bundleProperties = array( + 'http://www.w3.org/2000/01/rdf-schema#isDefinedBy' => url($schemaPath, array('absolute' => TRUE)), + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' => 'http://www.w3.org/2000/01/rdf-schema#class', + 'http://www.w3.org/2000/01/rdf-schema#subClassOf' => url("$schemaPath$entityType", array('absolute' => TRUE)), + ); + + $this->assertEqual($bundleSchema->getUri(), $bundleUri, 'Bundle term URI is generated correctly.'); + $this->assertEqual($bundleSchema->getProperties(), $bundleProperties, 'Bundle term properties are generated correctly.'); + } + +}