diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php index 6ff98f4..957bd4a 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php @@ -93,12 +93,12 @@ public function getTypeUri() { $bundle = $this->entity->bundle(); switch ($this->format) { case 'drupal_jsonld': - $schema_path = SiteSchema::CONTENT_DEPLOYMENT; + $schema_id = SiteSchema::CONTENT_DEPLOYMENT; break; case 'jsonld': - $schema_path = SiteSchema::SYNDICATION; + $schema_id = SiteSchema::SYNDICATION; } - $schema = $this->siteSchemaManager->getSchema($schema_path); + $schema = $this->siteSchemaManager->getSchema($schema_id); return $schema->bundle($entity_type, $bundle)->getUri(); } diff --git a/core/modules/rdf/lib/Drupal/rdf/BundleRdfMappingStorageController.php b/core/modules/rdf/lib/Drupal/rdf/BundleRdfMappingStorageController.php index ac4ea0c..051623a 100644 --- a/core/modules/rdf/lib/Drupal/rdf/BundleRdfMappingStorageController.php +++ b/core/modules/rdf/lib/Drupal/rdf/BundleRdfMappingStorageController.php @@ -13,7 +13,7 @@ class BundleRdfMappingStorageController extends RdfMappingStorageControllerBase protected function getTermSchema($entity) { // @todo Add exception for required properties. - return $this->siteSchema->bundle($entity->mappedEntityType, $entity->mappedBundle); + return $this->siteSchema->bundle($entity->entity_type, $entity->bundle); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/MappingSubscriber.php b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/MappingSubscriber.php index 7131efd..f58658d 100644 --- a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/MappingSubscriber.php +++ b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/MappingSubscriber.php @@ -42,7 +42,7 @@ public function mapBundleForOutput(\Drupal\rdf\MapBundleForOutputEvent $event) { $site_schema_curie = $term_schema->getCurie(); $event->addTypes(array($site_schema_curie)); - $config = config('rdf.mapping.bundle.' . $term_schema->getMappingConfigId()); + $config = config($term_schema->getMappingConfigName()); $types = $config->get('types'); if (!empty($types)) { $event->addTypes($types); @@ -56,7 +56,7 @@ public function mapFieldForOutput(\Drupal\rdf\MapFieldForOutputEvent $event) { $site_schema_curie = $term_schema->getCurie(); $event->addPredicates(array($site_schema_curie)); - $config = config('rdf.mapping.field.' . $term_schema->getMappingConfigId()); + $config = config($term_schema->getMappingConfigName()); $curies = $config->get('properties'); if (!empty($curies)) { $event->addPredicates($curies); diff --git a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php index 123493b..cf04c94 100644 --- a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php +++ b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php @@ -50,10 +50,10 @@ public function routes(RouteBuildEvent $event) { foreach ($this->siteSchemaManager->getSchemas() as $schema) { $routes = $schema->getRoutes(); foreach ($routes as $controller => $pattern) { - $schema_path = $schema->getPath(); + $schema_id = $schema->getId(); $route = new Route($pattern, array( '_controller' => 'Drupal\rdf\SiteSchema\SchemaController::' . $controller, - 'schema_path' => $schema_path, + 'schema_id' => $schema_id, ), array( '_method' => 'GET', '_access' => 'TRUE', @@ -61,7 +61,7 @@ public function routes(RouteBuildEvent $event) { // 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)); + $route_name = 'rdf.' . str_replace(array('-','/'), array('_', '.'), substr_replace($schema_id ,"",-1)); $collection->add($route_name, $route); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/FieldRdfMappingStorageController.php b/core/modules/rdf/lib/Drupal/rdf/FieldRdfMappingStorageController.php index 83119e3..04b5b7f 100644 --- a/core/modules/rdf/lib/Drupal/rdf/FieldRdfMappingStorageController.php +++ b/core/modules/rdf/lib/Drupal/rdf/FieldRdfMappingStorageController.php @@ -14,7 +14,7 @@ class FieldRdfMappingStorageController extends RdfMappingStorageControllerBase { protected function getTermSchema($entity) { // @todo Add exception for required properties. - return $this->siteSchema->field($entity->mappedEntityType, $entity->mappedBundle, $entity->mappedField); + return $this->siteSchema->field($entity->entity_type, $entity->bundle, $entity->field_name); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/MapFieldForOutputEvent.php b/core/modules/rdf/lib/Drupal/rdf/MapFieldForOutputEvent.php index afa1d9a..2294c3a 100644 --- a/core/modules/rdf/lib/Drupal/rdf/MapFieldForOutputEvent.php +++ b/core/modules/rdf/lib/Drupal/rdf/MapFieldForOutputEvent.php @@ -27,7 +27,7 @@ class MapFieldForOutputEvent extends Event { protected $datatype; - protected $datatypeCallback; + protected $datatype_callback; /** * Constructor. @@ -66,6 +66,6 @@ public function getDatatype() { } public function getDatatypeCallback() { - return $this->datatypeCallback; + return $this->datatype_callback; } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/BundleRdfMapping.php b/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/BundleRdfMapping.php index 3e8a0d0..ec30afd 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/BundleRdfMapping.php +++ b/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/BundleRdfMapping.php @@ -38,21 +38,28 @@ class BundleRdfMapping extends ConfigEntityBase { public $mid; /** - * The entity type of the mapped bundle. + * The schema of the mapped site schema term. * * @var string */ - public $mappedEntityType; + public $schema_id; /** - * The name of the mapped bundle. + * The entity type of the corresponding bundle. * * @var string */ - public $mappedBundle; + public $entity_type; /** - * The mapped RDF types. + * The site schema term's corresponding bundle. + * + * @var string + */ + public $bundle; + + /** + * The types that are being mapped to this site schema term. * * @var array */ diff --git a/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/FieldRdfMapping.php b/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/FieldRdfMapping.php index 502c1c2..7c1dc1c 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/FieldRdfMapping.php +++ b/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/FieldRdfMapping.php @@ -38,25 +38,32 @@ class FieldRdfMapping extends ConfigEntityBase { public $mid; /** - * The entity type of the bundle the mapped field is attached to. + * The schema of the mapped site schema term. * * @var string */ - public $mappedEntityType; + public $schema_id; /** - * The the bundle the mapped field is attached to. + * The entity type of the bundle that the corresponding field is attached to. * * @var string */ - public $mappedBundle; + public $entity_type; /** - * The name of the mapped field. + * The bundle that the corresponding field is attached to. * * @var string */ - public $mappedField; + public $bundle; + + /** + * The site schema term's corresponding field. + * + * @var string + */ + public $field_name; /** * The RDF properties the field is mapped to. @@ -77,7 +84,7 @@ class FieldRdfMapping extends ConfigEntityBase { * * @var callable */ - public $datatypeCallback; + public $datatype_callback; /** * Implements Drupal\Core\Entity\EntityInterface::id(). diff --git a/core/modules/rdf/lib/Drupal/rdf/RdfMappingManager.php b/core/modules/rdf/lib/Drupal/rdf/RdfMappingManager.php index 2fc262a..6ab6341 100644 --- a/core/modules/rdf/lib/Drupal/rdf/RdfMappingManager.php +++ b/core/modules/rdf/lib/Drupal/rdf/RdfMappingManager.php @@ -84,70 +84,31 @@ public function getTypedDataIdsFromTypeUris($input_rdf_types) { * The entity type of the bundle which the types correspond to. * @param string $bundle * The name of the bundle which the types correspond to. - * @param string $schema_path + * @param string $schema_id * The site schema which is being mapped to. */ - public function getBundleMapping($entity_type, $bundle, $schema_path = SiteSchema::SYNDICATION) { - $site_schema = $this->siteSchemaManager->getSchema($schema_path); + public function getBundleMapping($entity_type, $bundle, $schema_id = SiteSchema::SYNDICATION) { + $site_schema = $this->siteSchemaManager->getSchema($schema_id); $term_schema = $site_schema->bundle($entity_type, $bundle); // Get the site schema URI which corresponds to the bundle. $curies = $this->mapBundleForOutput($term_schema); return $curies; } - public function getFieldMapping($entity_type, $bundle, $field_name, $schema_path = SiteSchema::SYNDICATION) { - $site_schema = $this->siteSchemaManager->getSchema($schema_path); + public function getFieldMapping($entity_type, $bundle, $field_name, $schema_id = SiteSchema::SYNDICATION) { + $site_schema = $this->siteSchemaManager->getSchema($schema_id); $term_schema = $site_schema->field($entity_type, $bundle, $field_name); return $this->mapFieldForOutput($term_schema); } - public function saveBundleMappingConfig($mapping, $entity_type, $bundle) { - $keys = array( - 'mappedEntityType' => $entity_type, - 'mappedBundle' => $bundle, - ); - $bundle_mapping = entity_create('rdf_mapping_bundle', $keys); - if (isset($mapping['types'])) { - $bundle_mapping->types = $mapping['types']; - } - $bundle_mapping->save(); - } - - public function saveFieldMappingConfig($mapping, $entity_type, $bundle, $field_name) { - $keys = array( - 'mappedEntityType' => $entity_type, - 'mappedBundle' => $bundle, - 'mappedField' => $field_name, - ); - $field_mapping = entity_create('rdf_mapping_field', $keys); - if (isset($mapping['properties'])) { - $field_mapping->properties = $mapping['properties']; - } - if (isset($mapping['datatype'])) { - $field_mapping->datatype = $mapping['datatype']; - } - if (isset($mapping['datatype_callback'])) { - $field_mapping->datatypeCallback = $mapping['datatype_callback']; - } - $field_mapping->save(); - } - - public function deleteBundleMappingConfig($entity_type, $bundle) { - // Config can only be stored for the syndication schema. - $schema = $this->siteSchemaManager->getSchema(SiteSchema::SYNDICATION); - $bundle_schema = $schema->bundle($entity_type, $bundle); - $config_id = $bundle_schema->getMappingConfigId(); - $config = config("rdf.mapping.bundle.$config_id"); - $config->delete(); + public function getBundleMappingConfig($entity_type, $bundle, $schema_id = SiteSchema::SYNDICATION) { + $bundle_schema = $this->siteSchemaManager->getSchema($schema_id)->bundle($entity_type, $bundle); + return $bundle_schema->getMappingConfig(); } - public function deleteFieldMappingConfig($entity_type, $bundle, $field_name) { - // Config can only be stored for the syndication schema. - $schema = $this->siteSchemaManager->getSchema(SiteSchema::SYNDICATION); - $field_schema = $schema->field($entity_type, $bundle, $field_name); - $config_id = $field_schema->getMappingConfigId(); - $config = config("rdf.mapping.field.$config_id"); - $config->delete(); + public function getFieldMappingConfig($entity_type, $bundle, $field_name, $schema_id = SiteSchema::SYNDICATION) { + $field_schema = $this->siteSchemaManager->getSchema($schema_id)->field($entity_type, $bundle, $field_name); + return $field_schema->getMappingConfig(); } /** diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/BundleSchema.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/BundleSchema.php index 79dcdd5..e82b9ed 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/BundleSchema.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/BundleSchema.php @@ -22,6 +22,8 @@ class BundleSchema extends EntitySchema { */ public static $uriPattern = '{entity_type}/{bundle}'; + protected $configPrefix = 'rdf.mapping.bundle'; + /** * The bundle that this term identifies. * @@ -64,4 +66,10 @@ public function getProperties() { return $properties; } + protected function getMappingConfigKeys() { + $keys = parent::getMappingConfigKeys(); + $keys['bundle'] = $this->bundle; + return $keys; + } + } diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php index e951e4b..a1665e8 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/EntitySchema.php @@ -70,4 +70,11 @@ public function getProperties() { return $properties; } + protected function getMappingConfigKeys() { + return array( + 'schema_id' => $this->siteSchema->getId(), + 'entity_type' => $this->entityType, + ); + } + } diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/FieldSchema.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/FieldSchema.php index ca0c426..0d56ca5 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/FieldSchema.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/FieldSchema.php @@ -22,6 +22,8 @@ class FieldSchema extends SchemaTermBase { */ public static $uriPattern = '{entity_type}/{bundle}/{field_name}'; + protected $configPrefix = 'rdf.mapping.field'; + /** * The entity type that this term identifies. * @@ -91,4 +93,13 @@ public function getProperties() { return $properties; } + protected function getMappingConfigKeys() { + return array( + 'schema_id' => $this->siteSchema->getId(), + 'entity_type' => $this->entityType, + 'bundle' => $this->bundle, + 'field_name' => $this->fieldName, + ); + } + } diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php index b60eb84..9617401 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php @@ -42,7 +42,7 @@ public function setContainer(ContainerInterface $container = NULL) { * The entity type. * @param string $bundle * The entity bundle. - * @param string $schema_path + * @param string $schema_id * The relative base path for the schema. * * @return \Symfony\Component\HttpFoundation\Response @@ -50,7 +50,7 @@ public function setContainer(ContainerInterface $container = NULL) { * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ - public function bundle($entity_type, $bundle, $schema_path) { + public function bundle($entity_type, $bundle, $schema_id) { if (!$entity_info = entity_get_info($entity_type)) { throw new NotFoundHttpException(t('Entity type @entity_type not found', array('@entity_type' => $entity_type))); } @@ -60,7 +60,7 @@ public function bundle($entity_type, $bundle, $schema_path) { $serializer = $this->container->get('serializer'); $site_schema_manager = $this->container->get('rdf.site_schema_manager'); - $schema = $site_schema_manager->getSchema($schema_path); + $schema = $site_schema_manager->getSchema($schema_id); // @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/lib/Drupal/rdf/SiteSchema/SchemaTermBase.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaTermBase.php index c7a3339..edc7c34 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaTermBase.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaTermBase.php @@ -28,6 +28,8 @@ */ protected $siteSchema; + protected $configPrefix; + /** * Constructor. * @@ -58,8 +60,26 @@ public function getProperties() { ); } - public function getMappingConfigId() { - return str_replace('/', ':', $this->getPath()); + public function getMappingConfig() { + $config_name = $this->getMappingConfigName(); + $config = config($config_name); + + // If the entity type isn't set, then the config didn't exist before and the + // config factory created a new config entity. Fill in the keys and save it. + $entity_type = $config->get('entity_type'); + if (empty($entity_type)) { + $config->mid = $config_name; + foreach ($this->getMappingConfigKeys() as $key => $value) { + $config->set($key, $value); + } + $config->save(); + } + + return $config; + } + + public function getMappingConfigName() { + return $this->configPrefix . '.' . implode(':', $this->getMappingConfigKeys()); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php index b808826..dbb36d1 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchema.php @@ -19,8 +19,8 @@ class SiteSchema { // are not intended to be extensible. If a site wants to use external // vocabulary terms, the appropriate way to do this is to use the RDF mapping // system. - const CONTENT_DEPLOYMENT = 'site-schema/content-deployment/'; - const SYNDICATION = 'site-schema/syndication/'; + const CONTENT_DEPLOYMENT = 'content-deployment'; + const SYNDICATION = 'syndication'; /** * The relative base path of the instantiated schema. @@ -29,23 +29,26 @@ class SiteSchema { */ protected $schemaPath; + protected $schemaId; + protected $prefix; /** * Constructor. * - * @param string $schema_path + * @param string $schema_id * The schema path constant, used to determine which schema to instantiate. * * @throws \UnexpectedValueException */ - public function __construct($schema_path) { + public function __construct($schema_id) { $valid_paths = array(self::CONTENT_DEPLOYMENT, self::SYNDICATION); - if (!in_array($schema_path, $valid_paths)) { - throw new \UnexpectedValueException(sprintf('%s is not a valid site schema path. Schema path must be one of %s.'), $schema_path, implode(', ', $valid_paths)); + if (!in_array($schema_id, $valid_paths)) { + throw new \UnexpectedValueException(sprintf('%s is not a valid site schema path. Schema path must be one of %s.'), $schema_id, implode(', ', $valid_paths)); } - $this->schemaPath = $schema_path; - $this->prefix = ($schema_path == self::CONTENT_DEPLOYMENT) ? 'site-cd' : 'site-syn'; + $this->schemaId = $schema_id; + $this->schemaPath = 'site-schema/' . $schema_id . '/'; + $this->prefix = ($schema_id == self::CONTENT_DEPLOYMENT) ? 'site-cd' : 'site-syn'; } /** @@ -79,6 +82,10 @@ public function getUri() { return url($this->schemaPath, array('absolute' => TRUE)); } + public function getId() { + return $this->schemaId; + } + /** * Get the relative base path of the schema. */ diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchemaManager.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchemaManager.php index 7ca9ca8..6caa8fd 100644 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchemaManager.php +++ b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SiteSchemaManager.php @@ -65,8 +65,8 @@ public function getSchemas() { return $this->siteSchemas; } - public function getSchema($schema_path) { - return $this->siteSchemas[$schema_path]; + public function getSchema($schema_id) { + return $this->siteSchemas[$schema_id]; } /** diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php index ee256e2..3fafc3b 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php @@ -34,54 +34,53 @@ public static function getInfo() { */ function testCRUD() { $entity_type = $bundle = 'entity_test'; - $bundle_mapping_config_name = "rdf.mapping.bundle.site-schema:syndication:$entity_type:$bundle"; - $field_mapping_config_name = "rdf.mapping.field.site-schema:syndication:$entity_type:$bundle:user_id"; - - // Create mapping arrays to save. - $bundle_mapping = array( - 'types' => array('sioc:Post'), - ); - $user_id_mapping = array( - 'properties' => array('sioc:has_creator', 'dc:creator'), - ); - - // Save mappings. $mapping_manager = drupal_container()->get('rdf.mapping_manager'); - $mapping_manager->saveBundleMappingConfig($bundle_mapping, $entity_type, $bundle); - $mapping_manager->saveFieldMappingConfig($user_id_mapping, $entity_type, $bundle, 'user_id'); + $bundle_mapping_config_name = "rdf.mapping.bundle.syndication:$entity_type:$bundle"; + $user_id_mapping_config_name = "rdf.mapping.field.syndication:$entity_type:$bundle:user_id"; + + // Save bundle mapping config. + $bundle_mapping = $mapping_manager->getBundleMappingConfig($entity_type, $bundle); + $bundle_mapping->set('types', array('sioc:Post'))->save(); + // Save field mapping config. + $user_id_mapping = $mapping_manager->getFieldMappingConfig($entity_type, $bundle, 'user_id'); + $user_id_mapping->set('properties', array('sioc:has_creator', 'dc:creator'))->save(); // Test that config files were saved. $bundle_mapping_configs = config_get_storage_names_with_prefix('rdf.mapping.bundle'); $this->assertTrue(in_array($bundle_mapping_config_name, $bundle_mapping_configs), 'Bundle mapping config saved.'); $field_mapping_configs = config_get_storage_names_with_prefix('rdf.mapping.field'); - $this->assertTrue(in_array($field_mapping_config_name, $field_mapping_configs), 'Field mapping config saved.'); + $this->assertTrue(in_array($user_id_mapping_config_name, $field_mapping_configs), 'Field mapping config saved.'); - // Test that config was property saved. - $types = config($bundle_mapping_config_name)->get('types'); - $this->assertTrue(in_array('sioc:Post', $types), 'Bundle mapping config values saved correctly.'); - $properties = config($field_mapping_config_name)->get('properties'); - $this->assertTrue(in_array('sioc:has_creator', $properties) && in_array('dc:creator', $properties), 'Field mapping config values saved correctly.'); + // Test that config can be loaded. + $loaded_bundle_config = $mapping_manager->getBundleMappingConfig($entity_type, $bundle); + $bundle_config_array = $loaded_bundle_config->get(); + $this->assertTrue(!empty($bundle_config_array), 'Bundle mapping config loaded.'); + $loaded_field_config = $mapping_manager->getFieldMappingConfig($entity_type, $bundle, 'user_id'); + $field_config_array = $loaded_field_config->get(); + $this->assertTrue(!empty($field_config_array), 'Field mapping config loaded.'); - // Test loading of saved mapping. - $loaded_mapping = $mapping_manager->getBundleMapping($entity_type, $bundle); - $this->assertTrue(in_array('sioc:Post', $loaded_mapping['types']), 'Bundle mapping loaded.'); - $loaded_mapping = $mapping_manager->getFieldMapping($entity_type, $bundle, 'user_id'); - $this->assertTrue(in_array('sioc:has_creator', $loaded_mapping['properties']) && in_array('dc:creator', $loaded_mapping['properties']), 'Field mapping config loaded.'); + // Test that the values were saved correctly. + $types = config($bundle_mapping_config_name)->get('types'); + $this->assertTrue(in_array('sioc:Post', $types), 'Bundle mapping config values set properly.'); + $properties = config($user_id_mapping_config_name)->get('properties'); + $this->assertTrue(in_array('sioc:has_creator', $properties) && in_array('dc:creator', $properties), 'Field mapping config values set properly.'); // Test that mapping can be updated. - $user_id_mapping = array( - 'properties' => array('schema:author'), - ); - $mapping_manager->saveFieldMappingConfig($user_id_mapping, $entity_type, $bundle, 'user_id'); - $loaded_mapping = $mapping_manager->getFieldMapping($entity_type, $bundle, 'user_id'); - $this->assert(in_array('schema:author', $loaded_mapping['properties']) && !in_array('sioc:has_creator', $loaded_mapping['properties']), 'Mapping was updated.'); + $bundle_mapping->set('types', array('schema:Thing'))->save(); + $loaded_bundle_config = $mapping_manager->getBundleMappingConfig($entity_type, $bundle); + $types = $loaded_bundle_config->get('types'); + $this->assert(in_array('schema:Thing', $types) && !in_array('sioc:Post', $types), 'Bundle mapping was updated.'); + $user_id_mapping->set('properties', array('schema:author'))->save(); + $loaded_config = $mapping_manager->getFieldMappingConfig($entity_type, $bundle, 'user_id'); + $properties = $loaded_config->get('properties'); + $this->assert(in_array('schema:author', $properties) && !in_array('sioc:has_creator', $properties), 'Field mapping was updated.'); // Test that the mapping can be deleted. - $mapping_manager->deleteBundleMappingConfig($entity_type, $bundle); + $bundle_mapping->delete(); $bundle_mapping_configs = config_get_storage_names_with_prefix('rdf.mapping.bundle'); $this->assertFalse(in_array($bundle_mapping_config_name, $bundle_mapping_configs), 'Bundle mapping config deleted.'); - $mapping_manager->deleteFieldMappingConfig($entity_type, $bundle, 'user_id'); + $user_id_mapping->delete(); $field_mapping_configs = config_get_storage_names_with_prefix('rdf.mapping.field'); - $this->assertFalse(in_array($field_mapping_config_name, $field_mapping_configs), 'Field mapping config deleted.'); + $this->assertFalse(in_array($user_id_mapping_config_name, $field_mapping_configs), 'Field mapping config deleted.'); } } diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 95d029d..2325c14 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -405,7 +405,7 @@ function standard_install() { config('system.theme')->set('admin', 'seven')->save(); variable_set('node_admin_theme', '1'); - // Insert default pre-defined RDF mapping into the database. + // Save the RDF mapping configuration. $rdf_mapping_manager = drupal_container()->get('rdf.mapping_manager'); $bundle_mapping = array( 'types' => array('foaf:Document', 'sioc:Item'), @@ -446,9 +446,15 @@ function standard_install() { ); // Save the bundle mapping and shared field mappings for both node bundles. foreach (array('article', 'page') as $bundle) { - $rdf_mapping_manager->saveBundleMappingConfig($bundle_mapping, 'node', $bundle); + // Save bundle mapping config. + $config = $rdf_mapping_manager->getBundleMappingConfig('node', $bundle); + $bundle_mapping = array_merge($config->get(), $bundle_mapping); + $config->setData($bundle_mapping)->save(); + // Iterate over shared field mappings and save. foreach ($shared_field_mappings as $field_name => $field_mapping) { - $rdf_mapping_manager->saveFieldMappingConfig($field_mapping, 'node', $bundle, $field_name); + $config = $rdf_mapping_manager->getFieldMappingConfig('node', $bundle, $field_name); + $field_mapping = array_merge($config->get(), $field_mapping); + $config->setData($field_mapping)->save(); } } @@ -461,7 +467,12 @@ function standard_install() { 'properties' => array('dc:subject'), 'type' => 'rel', ); - $rdf_mapping_manager->saveFieldMappingConfig($field_image_mapping, 'node', 'article', 'field_image'); - $rdf_mapping_manager->saveFieldMappingConfig($field_tags_mapping, 'node', 'article', 'field_tags'); - + // Save field_image mapping. + $config = $rdf_mapping_manager->getFieldMappingConfig('node', 'article', 'field_image'); + $field_mapping = array_merge($config->get(), $field_image_mapping); + $config->setData($field_mapping)->save(); + // Save field_tags mapping. + $rdf_mapping_manager->getFieldMappingConfig('node', 'article', 'field_tags'); + $field_mapping = array_merge($config->get(), $field_tags_mapping); + $config->setData($field_mapping)->save(); }