From f406799a7737af274a28f0e02bd2b827dbd2ffe2 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 9 May 2013 22:58:27 +0100 Subject: [PATCH] Issue #1935548 by linclark, c4rl: Remove JSON-LD module. --- core/MAINTAINERS.txt | 3 - core/modules/jsonld/jsonld.info.yml | 9 - core/modules/jsonld/jsonld.module | 20 -- core/modules/jsonld/jsonld.services.yml | 39 ---- .../EventSubscriber/JsonldSubscriber.php | 42 ---- .../lib/Drupal/jsonld/JsonldEncoder.php | 40 ---- .../Drupal/jsonld/JsonldEntityNormalizer.php | 155 ------------- .../JsonldEntityReferenceNormalizer.php | 61 ----- .../lib/Drupal/jsonld/JsonldEntityWrapper.php | 131 ----------- .../jsonld/JsonldFieldItemNormalizer.php | 42 ---- .../Drupal/jsonld/JsonldNormalizerBase.php | 80 ------- .../jsonld/JsonldRdfSchemaNormalizer.php | 51 ----- .../jsonld/Tests/JsonldTestSetupHelper.php | 99 -------- .../jsonld/Tests/NormalizeDenormalizeTest.php | 213 ------------------ .../Tests/RdfSchemaSerializationTest.php | 56 ----- .../Tests/SupportsSerializationTest.php | 96 -------- .../rdf/EventSubscriber/RouteSubscriber.php | 78 ------- .../rdf/SiteSchema/SchemaController.php | 69 ------ core/modules/rdf/rdf.services.yml | 5 - 19 files changed, 1289 deletions(-) delete mode 100644 core/modules/jsonld/jsonld.info.yml delete mode 100644 core/modules/jsonld/jsonld.module delete mode 100644 core/modules/jsonld/jsonld.services.yml delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php delete mode 100644 core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php delete mode 100644 core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php delete mode 100644 core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php diff --git a/core/MAINTAINERS.txt b/core/MAINTAINERS.txt index 5cd608036cbf..dcec5e100e62 100644 --- a/core/MAINTAINERS.txt +++ b/core/MAINTAINERS.txt @@ -255,9 +255,6 @@ Help module Image module - Nathan Haug 'quicksketch' http://drupal.org/user/35821 -JSON-LD module -- Lin Clark 'linclark' http://drupal.org/user/396253 - Locale module - Gábor Hojtsy 'Gábor Hojtsy' http://drupal.org/user/4166 diff --git a/core/modules/jsonld/jsonld.info.yml b/core/modules/jsonld/jsonld.info.yml deleted file mode 100644 index c0623b660413..000000000000 --- a/core/modules/jsonld/jsonld.info.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: JSON-LD -type: module -description: 'Serializes entities using JSON-LD format.' -package: Core -version: VERSION -core: 8.x -dependencies: - - rdf - - serialization diff --git a/core/modules/jsonld/jsonld.module b/core/modules/jsonld/jsonld.module deleted file mode 100644 index b839e88bf693..000000000000 --- a/core/modules/jsonld/jsonld.module +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/** - * @file - * Enables entity serialization in JSON-LD. - */ - -/** - * Implements hook_help(). - */ -function jsonld_help($path, $args) { - switch ($path) { - case 'admin/help#jsonld': - $output = ''; - $output .= '<p>' . t('The JSON-LD module serializes entities to the <a href="@jsonld_org">JSON-LD</a> data format. To request JSON-LD instead of HTML, a client should add an Accept header to the request. This module will respond with JSON-LD if the Accept header value is one of the following: application/ld+json, which returns an easy-to-use data structure which is compatible with many external schemas, and application/vnd.drupal.ld+json, which is more expressive and is appropriate for content staging.', array( - '@jsonld_org' => 'http://json-ld.org/', - )) . '</p>'; - return $output; - } -} diff --git a/core/modules/jsonld/jsonld.services.yml b/core/modules/jsonld/jsonld.services.yml deleted file mode 100644 index 0359859ee91e..000000000000 --- a/core/modules/jsonld/jsonld.services.yml +++ /dev/null @@ -1,39 +0,0 @@ -# Normalizers can be specified to support a particular class and format in -# Normalizer::supportsNormalization(). Since the first matching Normalizer -# is used, Normalizers should be ordered from most specific to least -# specific. -services: - serializer.normalizer.entity_reference.jsonld: - class: Drupal\jsonld\JsonldEntityReferenceNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] - serializer.normalizer.field_item.jsonld: - class: Drupal\jsonld\JsonldFieldItemNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] - serializer.normalizer.entity.jsonld: - class: Drupal\jsonld\JsonldEntityNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] - serializer.normalizer.rdf_schema.jsonld: - class: Drupal\jsonld\JsonldRdfSchemaNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] -# Add the encoder to the service container. Encoders can only specify which -# format they support in Encoder::supportsEncoding(). - serializer.encoder.jsonld: - class: Drupal\jsonld\JsonldEncoder - tags: - - { name: encoder, priority: 5, format: jsonld } - serializer.encoder.drupal_jsonld: - class: Drupal\jsonld\JsonldEncoder - tags: - - { name: encoder, priority: 5, format: drupal_jsonld } - jsonld.subscriber: - class: Drupal\jsonld\EventSubscriber\JsonldSubscriber - tags: - - { name: event_subscriber } diff --git a/core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php b/core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php deleted file mode 100644 index 38a06ec6056e..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\jsonld\EventSubscriber\JsonldSubscriber. - */ - -namespace Drupal\jsonld\EventSubscriber; - -use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * Subscribes to the kernel request event to add JSON-LD media formats. - */ -class JsonldSubscriber implements EventSubscriberInterface { - - /** - * Registers JSON-LD formats with the Request class. - * - * @param Symfony\Component\HttpKernel\Event\GetResponseEvent $event - * The event to process. - */ - public function onKernelRequest(GetResponseEvent $event) { - $request = $event->getRequest(); - $request->setFormat('drupal_jsonld', 'application/vnd.drupal.ld+json'); - $request->setFormat('jsonld', 'application/ld+json'); - } - - /** - * Registers the methods in this class that should be listeners. - * - * @return array - * An array of event listener definitions. - */ - static function getSubscribedEvents() { - $events[KernelEvents::REQUEST][] = array('onKernelRequest', 40); - return $events; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php deleted file mode 100644 index 8aa289e51db1..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\jsonld\JsonldEncoder. - */ - -namespace Drupal\jsonld; - -use Symfony\Component\Serializer\Encoder\JsonEncoder; - -/** - * Encodes JSON-LD data. - * - * Simply respond to JSON-LD requests using the JSON encoder. - */ -class JsonldEncoder extends JsonEncoder { - - /** - * The formats that this Encoder supports. - * - * @var array - */ - static protected $format = array('jsonld', 'drupal_jsonld'); - - /** - * Overrides \Symfony\Component\Serializer\Encoder\JsonEncoder::supportsEncoding() - */ - public function supportsEncoding($format) { - return in_array($format, static::$format); - } - - /** - * Overrides \Symfony\Component\Serializer\Encoder\JsonEncoder::supportsDecoding() - */ - public function supportsDecoding($format) { - return in_array($format, static::$format); - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php deleted file mode 100644 index 14e7e004e32f..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php +++ /dev/null @@ -1,155 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\jsonld\JsonldEntityNormalizer. - */ - -namespace Drupal\jsonld; - -use Drupal\jsonld\JsonldNormalizerBase; -use Drupal\rdf\RdfMappingException; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; -use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; - -/** - * Converts the Drupal entity object structure to JSON-LD array structure. - */ -class JsonldEntityNormalizer extends JsonldNormalizerBase implements DenormalizerInterface { - - /** - * The interface or class that this Normalizer supports. - * - * @var string - */ - protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\EntityInterface'; - - /** - * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() - */ - public function normalize($entity, $format = NULL, array $context = array()) { - $entity_wrapper = new JsonldEntityWrapper($entity, $format, $this->serializer, $this->siteSchemaManager); - - $attributes = $entity_wrapper->getProperties(); - $attributes = array( - '@id' => $entity_wrapper->getId(), - '@type' => $entity_wrapper->getTypeUri(), - ) + $attributes; - return $attributes; - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() - * - * @throws \Symfony\Component\Serializer\Exception\UnexpectedValueException - */ - public function denormalize($data, $class, $format = null, array $context = array()) { - if (!isset($data['@type'])) { - throw new UnexpectedValueException('JSON-LD @type parameter must be included.'); - } - - // Every bundle has a type, identified by URI. The incoming data should - // either include a type URI from this site's schema, or one of the type - // URIs in the incoming data must map to a site schema URI when passed - // through the RDF mapping manager. - $type_uris = is_array($data['@type']) ? $data['@type'] : array($data['@type']); - // If the RDF mapping manager can find a match to a site schema URI, it - // will return the corresponding Typed Data ids. Otherwise, throw an - // exception. - // @todo The @types might be CURIEs or aliases. Expand before trying to map. - try { - $typed_data_ids = $this->rdfMappingManager->getTypedDataIdsFromTypeUris($type_uris); - } - catch (RdfMappingException $e) { - throw new UnexpectedValueException($e->getMessage(), 0, $e); - } - - $values = array( - 'type' => $typed_data_ids['bundle'], - ); - // If the data specifies a default language, use it to create the entity. - if (isset($data['langcode'])) { - $values['langcode'] = $data['langcode'][LANGUAGE_NOT_SPECIFIED][0]['value']; - } - // Otherwise, if the default language is not specified but there are - // translations of field values, explicitly set the entity's default - // language to the site's default language. This is required to enable - // field translation on this entity. - else if ($this->containsTranslation($data)) { - $values['langcode'] = language(LANGUAGE_TYPE_CONTENT)->langcode; - } - $entity = entity_create($typed_data_ids['entity_type'], $values); - // Make sure all empty entity fields default to NULL, so that afterwards it - // is possible to determine which fields were part of the data (even if they - // are empty). - foreach ($entity as $name => $field) { - if ($field->isEmpty()) { - $field->setValue(NULL); - } - } - - // For each attribute in the JSON-LD, add the values as fields to the newly - // created entity. It is assumed that the JSON attribute names are the same - // as the site's field names. - // @todo Possibly switch to URI expansion of attribute names. - foreach ($data as $fieldName => $incomingFieldValues) { - // Skip the JSON-LD specific terms, which start with '@'. - if ($fieldName[0] === '@') { - continue; - } - // If the incoming value is an empty array we set the property to mark it - // for deletion. - if (empty($incomingFieldValues) && is_array($incomingFieldValues)) { - $entity->{$fieldName} = array(); - } - - // Figure out the designated class for this field type, which is used by - // the Serializer to determine which Denormalizer to use. - // @todo Is there a better way to get the field type's associated class? - $fieldItemClass = get_class($entity->get($fieldName)->offsetGet(0)); - - // Iterate through the language keyed values and add them to the entity. - // The vnd.drupal.ld+json mime type will always use language keys, per - // http://drupal.org/node/1838700. - foreach ($incomingFieldValues as $langcode => $incomingFieldItems) { - $fieldValue = $this->serializer->denormalize($incomingFieldItems, $fieldItemClass, $format); - $entity->getTranslation($langcode) - ->set($fieldName, $fieldValue); - } - } - return $entity; - } - - /** - * Determine whether incoming data contains translated content. - * - * @param array $data - * The incoming data. - * - * @return bool - * Whether or not this data contains translated content. - */ - protected function containsTranslation($data) { - // Langcodes which do not represent a translation of the entity. - $defaultLangcodes = array( - LANGUAGE_DEFAULT, - LANGUAGE_NOT_SPECIFIED, - LANGUAGE_NOT_APPLICABLE, - language(LANGUAGE_TYPE_CONTENT)->langcode, - ); - - // Combine the langcodes from the field value keys in a single array. - $fieldLangcodes = array(); - foreach ($data as $propertyName => $property) { - //@todo Once @context has been added, check whether this property - // corresponds to an annotation instead. This will allow us to support - // incoming data that doesn't use language annotations. - if ('@' !== $propertyName[0]) { - $fieldLangcodes += array_keys($property); - } - } - - $translationLangcodes = array_diff($fieldLangcodes, $defaultLangcodes); - return !empty($translationLangcodes); - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php deleted file mode 100644 index 28f47efbfa37..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\jsonld\JsonldEntityReferenceNormalizer. - */ - -namespace Drupal\jsonld; - -use Drupal\Core\Cache\DatabaseBackend; -use Drupal\Core\Entity\EntityNG; -use Drupal\jsonld\JsonldNormalizerBase; -use Drupal\rdf\SiteSchema\SiteSchemaManager; -use ReflectionClass; -use Symfony\Component\Serializer\Exception\RuntimeException; -use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; - -/** - * Converts an EntityReferenceItem to a JSON-LD array structure. - */ -class JsonldEntityReferenceNormalizer extends JsonldNormalizerBase implements DenormalizerInterface { - - /** - * The interface or class that this Normalizer supports. - * - * @var string - */ - protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Field\Type\EntityReferenceItem'; - - /** - * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() - */ - public function normalize($object, $format = NULL, array $context = array()) { - // @todo If an $options parameter is added to the serialize signature, as - // requested in https://github.com/symfony/symfony/pull/4938, then instead - // of creating the array of properties, we could simply call normalize and - // pass in the referenced entity with a flag that ensures it is rendered as - // a node reference and not a node definition. - $entity_wrapper = new JsonldEntityWrapper($object->entity, $format, $this->serializer, $this->siteSchemaManager); - return array( - '@id' => $entity_wrapper->getId(), - ); - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() - */ - public function denormalize($data, $class, $format = null, array $context = array()) { - // @todo Support denormalization for Entity Reference. - return array(); - } - - /** - * Overrides \Drupal\jsonld\JsonldNormalizerBase::supportsDenormalization() - */ - public function supportsDenormalization($data, $type, $format = NULL) { - $reflection = new ReflectionClass($type); - return in_array($format, static::$format) && ($reflection->getName() == $this->supportedInterfaceOrClass || $reflection->isSubclassOf($this->supportedInterfaceOrClass)); - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php deleted file mode 100644 index f96f1143d768..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\jsonld\JsonldEntityWrapper. - */ - -namespace Drupal\jsonld; - -use Drupal\Core\Entity\Entity; -use Drupal\rdf\SiteSchema\SiteSchema; -use Drupal\rdf\SiteSchema\SiteSchemaManager; -use Symfony\Component\Serializer\Serializer; - -/** - * Provide an interface for JsonldNormalizer to get required properties. - * - * @todo Eventually, this class should be removed. It allows both the - * EntityNormalizer and the EntityReferenceNormalizer to have access to the - * same functions. If an $options parameter is added to the serialize - * signature, as requested in https://github.com/symfony/symfony/pull/4938, - * then the EntityReferenceNormalizer could simply call - * EntityNormalizer::normalize(), passing in the referenced entity. - */ -class JsonldEntityWrapper { - - /** - * The entity that this object wraps. - * - * @var \Drupal\Core\Entity\EntityNG - */ - protected $entity; - - /** - * The requested format. - * - * @var string - */ - protected $format; - - /** - * The serializer. - * - * @var \Symfony\Component\Serializer\Serializer - */ - protected $serializer; - - /** - * The site schema manager. - * - * @var \Drupal\rdf\SiteSchema\SiteSchemaManager - */ - protected $siteSchemaManager; - - /** - * Constructor. - * - * @param \Drupal\Core\Entity\EntityNG $entity - * The Entity API entity - * @param string $format. - * The format. - * @param \Symfony\Component\Serializer\Serializer $serializer - * The serializer, provided by the SerializerAwareNormaizer. - * @param \Drupal\rdf\SiteSchema\SiteSchemaManager $site_schema_manager - * The site schema manager. - */ - public function __construct(Entity $entity, $format, Serializer $serializer, SiteSchemaManager $site_schema_manager) { - $this->entity = $entity; - $this->format = $format; - $this->serializer = $serializer; - $this->siteSchemaManager = $site_schema_manager; - } - - /** - * Get the Entity's URI for the @id attribute. - * - * @return string - * The URI of the entity. - */ - public function getId() { - $uri_info = $this->entity->uri(); - return url($uri_info['path'], array('absolute' => TRUE)); - } - - /** - * Get the type URI. - * - * @todo Once RdfMappingManager has a mapOutputTypes event, use that instead - * of simply returning the site schema URI. - */ - public function getTypeUri() { - $entity_type = $this->entity->entityType(); - $bundle = $this->entity->bundle(); - switch ($this->format) { - case 'drupal_jsonld': - $schema_path = SiteSchema::CONTENT_DEPLOYMENT; - break; - case 'jsonld': - $schema_path = SiteSchema::SYNDICATION; - } - $schema = $this->siteSchemaManager->getSchema($schema_path); - return $schema->bundle($entity_type, $bundle)->getUri(); - } - - /** - * Get properties, excluding JSON-LD specific properties. - * - * @return array - * An array of properties structured as in JSON-LD. - */ - public function getProperties() { - // Properties to skip. - $skip = array('id'); - $properties = array(); - - // Create language map property structure. - foreach ($this->entity->getTranslationLanguages() as $langcode => $language) { - foreach ($this->entity->getTranslation($langcode) as $name => $field) { - $definition = $this->entity->getPropertyDefinition($name); - $langKey = empty($definition['translatable']) ? LANGUAGE_NOT_SPECIFIED : $langcode; - if (!$field->isEmpty()) { - $properties[$name][$langKey] = $this->serializer->normalize($field, $this->format); - } - } - } - - // Only return properties which are not in the $skip array. - return array_diff_key($properties, array_fill_keys($skip, '')); - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php deleted file mode 100644 index 1f1a1bbac9ca..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\jsonld\JsonldFieldItemNormalizer. - */ - -namespace Drupal\jsonld; - -use Drupal\Core\Entity\Field\FieldItemInterface; -use Drupal\jsonld\JsonldNormalizerBase; -use Symfony\Component\Serializer\Exception\RuntimeException; -use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; - -/** - * Converts the Drupal entity object structure to JSON-LD array structure. - */ -class JsonldFieldItemNormalizer extends JsonldNormalizerBase implements DenormalizerInterface { - - /** - * The interface or class that this Normalizer supports. - * - * @var string - */ - protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Field\FieldItemInterface'; - - /** - * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() - */ - public function normalize($object, $format = NULL, array $context = array()) { - return $object->getPropertyValues(); - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() - */ - public function denormalize($data, $class, $format = null, array $context = array()) { - // For most fields, the field items array should simply be returned as is. - return $data; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php deleted file mode 100644 index 61741ee378ab..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php +++ /dev/null @@ -1,80 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\jsonld\JsonldNormalizerBase. - */ - -namespace Drupal\jsonld; - -use ReflectionClass; -use Drupal\rdf\RdfMappingManager; -use Drupal\rdf\SiteSchema\SiteSchemaManager; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer; - -/** - * Provide a base class for JSON-LD Normalizers. - */ -abstract class JsonldNormalizerBase extends SerializerAwareNormalizer implements NormalizerInterface { - - /** - * The interface or class that this Normalizer supports. - * - * @var string - */ - protected $supportedInterfaceOrClass; - - /** - * The formats that this Normalizer supports. - * - * @var array - */ - static protected $format = array('jsonld', 'drupal_jsonld'); - - /** - * The site schema manager. - * - * @var \Drupal\rdf\SiteSchema\SiteSchemaManager - */ - protected $siteSchemaManager; - - /** - * The RDF mapping manager. - * - * @var \Drupal\rdf\RdfMappingManager - */ - protected $rdfMappingManager; - - /** - * Constructor. - * - * @param \Drupal\rdf\SiteSchema\SiteSchemaManager $site_schema_manager - * The site schema manager. - * @param \Drupal\rdf\RdfMappingManager $rdf_mapping_manager - * The RDF mapping manager. - */ - public function __construct(SiteSchemaManager $site_schema_manager, RdfMappingManager $rdf_mapping_manager) { - $this->siteSchemaManager = $site_schema_manager; - $this->rdfMappingManager = $rdf_mapping_manager; - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() - */ - public function supportsNormalization($data, $format = NULL) { - return is_object($data) && in_array($format, static::$format) && ($data instanceof $this->supportedInterfaceOrClass); - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() - * - * This class doesn't implement DenormalizerInterface, but most of its child - * classes do, so this method is implemented at this level to reduce code - * duplication. - */ - public function supportsDenormalization($data, $type, $format = NULL) { - $reflection = new ReflectionClass($type); - return in_array($format, static::$format) && $reflection->implementsInterface($this->supportedInterfaceOrClass); - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php deleted file mode 100644 index 9315a58c7ca3..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -/** - * @file - * Contains JsonldRdfSchemaNormalizer. - */ - -namespace Drupal\jsonld; - -use Drupal\jsonld\JsonldNormalizerBase; -use Drupal\rdf\RdfConstants; - -/** - * Converts the Drupal entity object structure to JSONLD array structure. - */ -class JsonldRdfSchemaNormalizer extends JsonldNormalizerBase { - - /** - * The interface or class that this Normalizer supports. - * - * @var string - */ - protected $supportedInterfaceOrClass = 'Drupal\rdf\SiteSchema\SchemaTermBase'; - - /** - * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() - */ - public function normalize($data, $format = NULL, array $context = array()) { - $normalized = array(); - $graph = $data->getGraph(); - - foreach ($graph as $term_uri => $properties) { - // JSON-LD uses the @type keyword as a stand-in for rdf:type. Replace any - // use of rdf:type and move the type to the front of the property array. - if (isset($properties[RdfConstants::RDF_TYPE])) { - $properties = array( - '@type' => $properties[RdfConstants::RDF_TYPE], - ) + $properties; - } - unset($properties[RdfConstants::RDF_TYPE]); - - // Add the @id keyword to the front of the array. - $normalized[] = array( - '@id' => $term_uri, - ) + $properties; - } - - return $normalized; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php deleted file mode 100644 index bf3a33b3449b..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php +++ /dev/null @@ -1,99 +0,0 @@ -<?php - -/** - * @file - * Contains JsonldTestSetupHelper. - */ - -namespace Drupal\jsonld\Tests; - -use Drupal\jsonld\JsonldEncoder; -use Drupal\jsonld\JsonldEntityNormalizer; -use Drupal\jsonld\JsonldEntityReferenceNormalizer; -use Drupal\jsonld\JsonldFieldItemNormalizer; -use Drupal\rdf\RdfMappingManager; -use Drupal\rdf\EventSubscriber\MappingSubscriber; -use Drupal\rdf\SiteSchema\SiteSchemaManager; -use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\Serializer\Serializer; - -/** - * Constructs services for JSON-LD tests. - */ -class JsonldTestSetupHelper { - - /** - * The site schema manager. - * - * @var \Drupal\rdf\SiteSchema\SiteSchemaManager - */ - protected $siteSchemaManager; - - /** - * The RDF mapping manager. - * - * @var \Drupal\rdf\RdfMappingManager - */ - protected $rdfMappingManager; - - /** - * The Normalizer array. - * - * @var array - */ - protected $normalizers; - - /** - * Constructor. - * - * @param \Symfony\Component\DependencyInjection\Container $container - * The container. - */ - public function __construct(Container $container) { - // Construct site schema manager. - $this->siteSchemaManager = new SiteSchemaManager($container->get('cache.cache')); - // Construct RDF mapping manager. - $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber(new MappingSubscriber()); - $this->rdfMappingManager = new RdfMappingManager($dispatcher, $this->siteSchemaManager); - // Construct normalizers. - $this->normalizers = array( - 'entityreference' => new JsonldEntityReferenceNormalizer($this->siteSchemaManager, $this->rdfMappingManager), - 'field_item' => new JsonldFieldItemNormalizer($this->siteSchemaManager, $this->rdfMappingManager), - 'entity' => new JsonldEntityNormalizer($this->siteSchemaManager, $this->rdfMappingManager), - ); - $serializer = new Serializer($this->normalizers, array(new JsonldEncoder())); - $this->normalizers['entity']->setSerializer($serializer); - } - - /** - * Get Normalizers. - * - * @return array - * An array of normalizers, keyed by supported class or interface. - */ - public function getNormalizers() { - return $this->normalizers; - } - - /** - * Get the SiteSchemaManager object. - * - * @return \Drupal\rdf\SiteSchema\SiteSchemaManager - * The SiteSchemaManager, which is also injected into the Normalizers. - */ - public function getSiteSchemaManager() { - return $this->siteSchemaManager; - } - - /** - * Get the RdfMappingManager object. - * - * @return \Drupal\rdf\RdfMappingManager - * The RdfMappingManager, which is also injected into the Normalizers. - */ - public function getRdfMappingManager() { - return $this->rdfMappingManager; - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php deleted file mode 100644 index 0371ed98ce9f..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php +++ /dev/null @@ -1,213 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\jsonld\Tests\NormalizeDenormalizeTest. - */ - -namespace Drupal\jsonld\Tests; - -use Drupal\Core\Language\Language; -use Drupal\rdf\SiteSchema\SiteSchema; -use Drupal\simpletest\WebTestBase; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; - -/** - * Test the vendor specific JSON-LD normalizer. - * - * This is implemented as a WebTest because it requires use of the Entity API. - */ -class NormalizeDenormalizeTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('entity_test', 'jsonld', 'language', 'rdf'); - - /** - * The format being tested. - */ - protected static $format = 'drupal_jsonld'; - - /** - * The Normalizers to be tested. - */ - protected $normalizers; - - public static function getInfo() { - return array( - 'name' => 'Normalize/Denormalize Test', - 'description' => "Test that entities can be normalized/denormalized in JSON-LD.", - 'group' => 'JSON-LD', - ); - } - - /** - * Add the normalizer to be tested. - */ - function setUp() { - parent::setUp(); - - $setup_helper = new JsonldTestSetupHelper($this->container); - $this->normalizers = $setup_helper->getNormalizers(); - - // Add German as a language. - $language = new Language(array( - 'langcode' => 'de', - 'name' => 'Deutsch', - )); - language_save($language); - } - - /** - * Tests the normalize function. - */ - public function testNormalize() { - // Create a German entity. - $values = array( - 'langcode' => 'de', - 'name' => $this->randomName(), - 'user_id' => $GLOBALS['user']->uid, - 'field_test_text' => array( - 'value' => $this->randomName(), - 'format' => 'full_html', - ), - ); - // Array of translated values. - $translationValues = array( - 'name' => $this->randomName(), - ); - - $entity = entity_create('entity_test', $values); - $entity->save(); - // Add an English value for name property. - $entity->getTranslation('en')->set('name', array(0 => array('value' => $translationValues['name']))); - - $expectedArray = array( - '@id' => $this->getEntityId($entity), - 'uuid' => array( - 'und' => array( - array( - 'value' => $entity->uuid(), - ), - ), - ), - 'user_id' => array( - 'de' => array( - array( - '@id' => url('user/' . $values['user_id'], array('absolute' => TRUE)), - ), - ), - ), - 'name' => array( - 'de' => array( - array( - 'value' => $values['name'], - ), - ), - 'en' => array( - array( - 'value' => $translationValues['name'], - ), - ), - ), - 'field_test_text' => array( - 'und' => array( - array( - 'value' => $values['field_test_text']['value'], - 'format' => $values['field_test_text']['format'], - ), - ), - ), - ); - - $normalized = $this->normalizers['entity']->normalize($entity, static::$format); - // Test ordering. The @context and @id properties should always be first. - $keys = array_keys($normalized); - $this->assertEqual($keys[0], '@id', '@id and @context attributes placed correctly.'); - // Test @id value. - $this->assertEqual($normalized['@id'], $expectedArray['@id'], '@id uses correct value.'); - // Test non-translatable field. - $this->assertEqual($normalized['uuid'], $expectedArray['uuid'], 'Non-translatable fields are nested correctly.'); - // Test single-language translatable. - $this->assertEqual($normalized['user_id'], $expectedArray['user_id'], 'Translatable field with single language value is nested correctly.'); - // Test multi-language translatable. - $this->assertEqual($normalized['name'], $expectedArray['name'], 'Translatable field with multiple language values is nested correctly.'); - // Test multi-property untranslatable field. - $this->assertEqual($normalized['field_test_text'], $expectedArray['field_test_text'], 'Field with properties is nested correctly.'); - } - - function testDenormalize() { - $schema = new SiteSchema(SiteSchema::CONTENT_DEPLOYMENT); - $bundle_uri = $schema->bundle('entity_test', 'entity_test')->getUri(); - $incoming_data = array( - '@type' => $bundle_uri, - 'name' => array( - 'en' => array( - array( - 'value' => $this->randomName(), - ), - ), - 'de' => array( - array( - 'value' => $this->randomName(), - ), - ), - ), - 'field_test_text' => array( - 'und' => array( - array( - 'value' => $this->randomName(), - 'format' => 'full_html', - ), - ), - ), - ); - - // Test valid request. - $entity = $this->normalizers['entity']->denormalize($incoming_data, 'Drupal\Core\Entity\EntityNG', static::$format); - $this->assertEqual('entity_test', $entity->bundle(), "Denormalize creates entity with correct bundle."); - $this->assertEqual($incoming_data['name']['en'], $entity->get('name')->getValue(), "Translatable field denormalized correctly in default language."); - $this->assertEqual($incoming_data['name']['de'], $entity->getTranslation('de')->get('name')->getValue(), "Translatable field denormalized correctly in translation language."); - $this->assertEqual($incoming_data['field_test_text']['und'], $entity->get('field_test_text')->getValue(), "Untranslatable field denormalized correctly."); - - // Test request without @type. - unset($incoming_data['@type']); - try { - $this->normalizers['entity']->denormalize($incoming_data, 'Drupal\Core\Entity\EntityNG', static::$format); - $this->fail('Trying to denormalize entity data without @type results in exception.'); - } - catch (UnexpectedValueException $e) { - $this->pass('Trying to denormalize entity data without @type results in exception.'); - } - - // Test request with @type that has no valid mapping. - $incoming_data['@type'] = 'http://failing-uri.com/type'; - try { - $this->normalizers['entity']->denormalize($incoming_data, 'Drupal\Core\Entity\EntityNG', static::$format); - $this->fail('Trying to denormalize entity data with unrecognized @type results in exception.'); - } - catch (UnexpectedValueException $e) { - $this->pass('Trying to denormalize entity data with unrecognized @type results in exception.'); - } - } - - /** - * Get the Entity ID. - * - * @param \Drupal\Core\Entity\EntityNG $entity - * Entity to get URI for. - * - * @return string - * Return the entity URI. - */ - protected function getEntityId($entity) { - global $base_url; - $uriInfo = $entity->uri(); - return $base_url . '/' . $uriInfo['path']; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php deleted file mode 100644 index e5349f1fd5c5..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** - * @file - * Contains RdfSchemaSerializationTest. - */ - -namespace Drupal\jsonld\Tests; - -use Drupal\jsonld\JsonldRdfSchemaNormalizer; -use Drupal\jsonld\JsonldEncoder; -use Drupal\rdf\SiteSchema\BundleSchema; -use Drupal\rdf\SiteSchema\SiteSchema; -use Drupal\simpletest\DrupalUnitTestBase; -use Symfony\Component\Serializer\Serializer; - -class RdfSchemaSerializationTest extends DrupalUnitTestBase { - - public static $modules = array('system'); - - public static function getInfo() { - return array( - 'name' => 'Site schema JSON-LD serialization', - 'description' => 'Tests the JSON-LD serialization of the RDF site schema.', - 'group' => 'JSON-LD', - ); - } - - /** - * Tests the serialization of site schemas. - */ - function testSchemaSerialization() { - // url() requires the {url_alias} table. - $this->installSchema('system', 'url_alias'); - - $entity_type = $bundle = 'entity_test'; - - // Set up the bundle schema for the entity_test bundle. - $schema = new SiteSchema(SiteSchema::CONTENT_DEPLOYMENT); - $bundle_schema = $schema->bundle($entity_type, $bundle); - // Set up the serializer. - $setup_helper = new JsonldTestSetupHelper($this->container); - $normalizer = new JsonldRdfSchemaNormalizer($setup_helper->getSiteSchemaManager(), $setup_helper->getRdfMappingManager()); - $serializer = new Serializer(array($normalizer), array(new JsonldEncoder())); - - $serialized = $serializer->serialize($bundle_schema, 'jsonld'); - $decoded = json_decode($serialized); - $parsed_term = $decoded[0]; - - $this->assertEqual($parsed_term->{'@id'}, $bundle_schema->getUri(), 'JSON-LD for schema term uses correct @id.'); - $this->assertEqual($parsed_term->{'@type'}, 'http://www.w3.org/2000/01/rdf-schema#class', 'JSON-LD for schema term uses correct @type.'); - // The @id and @type should be placed in the beginning of the array. - $array_keys = array_keys((array) $parsed_term); - $this->assertEqual(array('@id', '@type'), array_slice($array_keys, 0, 2), 'JSON-LD keywords are placed before other properties.'); - $this->assertTrue(isset($parsed_term->{'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'}), 'Other properties of the term are included.'); - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php deleted file mode 100644 index d9d4a7fc1dc9..000000000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\jsonld\Tests\SupportsSerializationTest. - */ - -namespace Drupal\jsonld\Tests; - -use Drupal\config\Tests\ConfigEntityTest; -use Drupal\simpletest\WebTestBase; - -/** - * Test the vendor specific JSON-LD normalizer. - */ -class SupportsSerializationTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('entity_test', 'jsonld'); - - /** - * The format being tested. - */ - protected static $format = 'drupal_jsonld'; - - /** - * The Normalizers to be tested. - */ - protected $normalizers; - - public static function getInfo() { - return array( - 'name' => 'Supports class/format serialization test', - 'description' => "Test that normalizers and encoders support expected classes and formats.", - 'group' => 'JSON-LD', - ); - } - - /** - * Add the normalizer to be tested. - */ - function setUp() { - parent::setUp(); - - $setup_helper = new JsonldTestSetupHelper($this->container); - $this->normalizers = $setup_helper->getNormalizers(); - } - - /** - * Tests the supportsNormalization function. - */ - public function testSupportsNormalization() { - $format = static::$format; - $supportedEntity = entity_create('entity_test', array()); - $unsupportedEntity = new ConfigEntityTest(); - $field = $supportedEntity->get('uuid'); - $entityreferenceField = $supportedEntity->get('user_id'); - - // Supported entity. - $this->assertTrue($this->normalizers['entity']->supportsNormalization($supportedEntity, static::$format), "Entity normalization is supported for $format on content entities."); - // Unsupported entity. - $this->assertFalse($this->normalizers['entity']->supportsNormalization($unsupportedEntity, static::$format), "Normalization is not supported for other entity types."); - - // Field item. - $this->assertTrue($this->normalizers['field_item']->supportsNormalization($field->offsetGet(0), static::$format), "Field item normalization is supported for $format."); - // Entity reference field item. - $this->assertTrue($this->normalizers['entityreference']->supportsNormalization($entityreferenceField->offsetGet(0), static::$format), "Entity reference field item normalization is supported for $format."); - } - - /** - * Tests the supportsDenormalization function. - */ - public function testSupportsDenormalization() { - $format = static::$format; - $data = array(); - $supportedEntityClass = 'Drupal\Core\Entity\EntityNG'; - $unsupportedEntityClass = 'Drupal\config\Tests\ConfigEntityTest'; - $fieldClass = 'Drupal\Core\Entity\Field\Type\StringItem'; - $entityreferenceFieldClass = 'Drupal\Core\Entity\Field\Type\EntityReferenceItem'; - - // Supported entity. - $this->assertTrue($this->normalizers['entity']->supportsDenormalization($data, $supportedEntityClass, static::$format), "Entity denormalization is supported for $format on content entities."); - // Unsupported entity. - $this->assertFalse($this->normalizers['entity']->supportsDenormalization($data, $unsupportedEntityClass, static::$format), "Denormalization is not supported for other entity types."); - - // Field item. - $this->assertTrue($this->normalizers['field_item']->supportsDenormalization($data, $fieldClass, static::$format), "Field item denormalization is supported for $format."); - // Entity reference field item. - $this->assertTrue($this->normalizers['entityreference']->supportsDenormalization($data, $entityreferenceFieldClass, static::$format), "Entity reference field item denormalization is supported for $format."); - } - -} diff --git a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php deleted file mode 100644 index 123493bca336..000000000000 --- a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -/** - * @file - * Contains RouteSubscriber. - */ - -namespace Drupal\rdf\EventSubscriber; - -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Drupal\rdf\SiteSchema\SiteSchema; -use Drupal\rdf\SiteSchema\SiteSchemaManager; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\Routing\Route; - -/** - * Subscriber for site-generated schema routes. - */ -class RouteSubscriber implements EventSubscriberInterface { - - /** - * The site schema manager. - * - * @var \Drupal\rdf\SiteSchema\SiteSchemaManager - */ - protected $siteSchemaManager; - - /** - * Constructor. - * - * @param \Drupal\rdf\SiteSchema\SiteSchemaManager $site_schema_manager - * The injected site schema manager. - */ - public function __construct(SiteSchemaManager $site_schema_manager) { - $this->siteSchemaManager = $site_schema_manager; - } - - /** - * Adds routes for term types in the site-generated schemas. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - */ - public function routes(RouteBuildEvent $event) { - - $collection = $event->getRouteCollection(); - - // Add the routes for all of the terms in both schemas. - foreach ($this->siteSchemaManager->getSchemas() as $schema) { - $routes = $schema->getRoutes(); - foreach ($routes as $controller => $pattern) { - $schema_path = $schema->getPath(); - $route = new Route($pattern, array( - '_controller' => 'Drupal\rdf\SiteSchema\SchemaController::' . $controller, - 'schema_path' => $schema_path, - ), array( - '_method' => 'GET', - '_access' => 'TRUE', - )); - // 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. - $route_name = 'rdf.' . str_replace(array('-','/'), array('_', '.'), substr_replace($schema_path ,"",-1)); - $collection->add($route_name, $route); - } - } - } - - /** - * Implements EventSubscriberInterface::getSubscribedEvents(). - */ - static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } -} - diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php deleted file mode 100644 index acd3f8e85de4..000000000000 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -/** - * @file - * Contains SchemaController. - */ - -namespace Drupal\rdf\SiteSchema; - -use Drupal\rdf\SiteSchema\SiteSchema; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; - -/** - * Resource controller for displaying entity schemas. - */ -class SchemaController implements ContainerAwareInterface { - - /** - * The injection container for this object. - * - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - /** - * Injects the service container used by this object. - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * The service container this object should use. - */ - public function setContainer(ContainerInterface $container = NULL) { - $this->container = $container; - } - - /** - * Responds to a schema request for a bundle of a given entity type. - * - * @param string $entity_type - * The entity type. - * @param string $bundle - * The entity bundle. - * @param string $schema_path - * The relative base path for the schema. - * - * @return \Symfony\Component\HttpFoundation\Response - * The response object. - * - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - */ - public function bundle($entity_type, $bundle, $schema_path) { - if (!$entity_info = entity_get_info($entity_type)) { - throw new NotFoundHttpException(t('Entity type @entity_type not found', array('@entity_type' => $entity_type))); - } - if (!array_key_exists($bundle, entity_get_bundles($entity_type))) { - throw new NotFoundHttpException(t('Bundle @bundle not found', array('@bundle' => $bundle))); - } - - $serializer = $this->container->get('serializer'); - $site_schema_manager = $this->container->get('rdf.site_schema_manager'); - $schema = $site_schema_manager->getSchema($schema_path); - // @todo Remove hard-coded mimetype once we have proper conneg. - $content = $serializer->serialize($schema->bundle($entity_type, $bundle), 'jsonld'); - return new Response($content, 200, array('Content-type' => 'application/json')); - } - -} diff --git a/core/modules/rdf/rdf.services.yml b/core/modules/rdf/rdf.services.yml index 7b3a51550a76..97777203873c 100644 --- a/core/modules/rdf/rdf.services.yml +++ b/core/modules/rdf/rdf.services.yml @@ -9,8 +9,3 @@ services: class: Drupal\rdf\EventSubscriber\MappingSubscriber tags: - { name: event_subscriber } - rdf.route_subscriber: - class: Drupal\rdf\EventSubscriber\RouteSubscriber - tags: - - { name: event_subscriber } - arguments: ['@rdf.site_schema_manager'] -- GitLab