diff --git a/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/RdfMapping.php b/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/RdfMapping.php index eef17a5..d9f369f 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/RdfMapping.php +++ b/core/modules/rdf/lib/Drupal/rdf/Plugin/Core/Entity/RdfMapping.php @@ -76,7 +76,7 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface { /** * {@inheritdoc} */ - public function getBundleMapping() { + public function getPreparedBundleMapping() { $types = array(); if (isset($this->types)) { $types = $this->types; @@ -87,7 +87,7 @@ public function getBundleMapping() { /** * {@inheritdoc} */ - public function getBundleMappingConfig() { + public function getBundleMapping() { if (isset($this->types)) { return array('types' => $this->types); } @@ -97,7 +97,7 @@ public function getBundleMappingConfig() { /** * {@inheritdoc} */ - public function setBundleMappingConfig(array $mapping) { + public function setBundleMapping(array $mapping) { if (isset($mapping['types'])) { $this->types = $mapping['types']; } @@ -108,7 +108,7 @@ public function setBundleMappingConfig(array $mapping) { /** * {@inheritdoc} */ - public function getFieldMapping($field_name) { + public function getPreparedFieldMapping($field_name) { $field_mapping = array( 'properties' => NULL, 'datatype' => NULL, @@ -124,7 +124,7 @@ public function getFieldMapping($field_name) { /** * {@inheritdoc} */ - public function getFieldMappingConfig($field_name) { + public function getFieldMapping($field_name) { if (isset($this->fieldMappings[$field_name])) { return $this->fieldMappings[$field_name]; } @@ -134,7 +134,7 @@ public function getFieldMappingConfig($field_name) { /** * {@inheritdoc} */ - public function setFieldMappingConfig($field_name, array $mapping = array()) { + public function setFieldMapping($field_name, array $mapping = array()) { $this->fieldMappings[$field_name] = $mapping; return $this; } diff --git a/core/modules/rdf/lib/Drupal/rdf/RdfMappingInterface.php b/core/modules/rdf/lib/Drupal/rdf/RdfMappingInterface.php index 21ab065..19b1e13 100644 --- a/core/modules/rdf/lib/Drupal/rdf/RdfMappingInterface.php +++ b/core/modules/rdf/lib/Drupal/rdf/RdfMappingInterface.php @@ -16,30 +16,40 @@ /** * Gets the mapping for the bundle-level data. * + * The prepared bundle mapping should be used when outputting data in RDF + * serializations such as RDFa. In the prepared mapping, the mapping + * configuration's CURIE arrays are processed into CURIE strings suitable for + * output. + * * @return array * The bundle mapping. */ - public function getBundleMapping(); + public function getPreparedBundleMapping(); /** * Gets the mapping config for the bundle-level data. * + * This function returns the bundle mapping as stored in config, which may + * contain CURIE arrays. If the mapping is needed for output in a + * serialization format, such as RDFa, then getPreparedBundleMapping() should + * be used instead. + * * @return array|null * The bundle mapping, or NULL if there is no mapping. */ - public function getBundleMappingConfig(); + public function getBundleMapping(); /** - * Sets the mapping config for a bundle. + * Sets the mapping config for the bundle-level data. * * This only sets bundle-level mappings, such as the RDF type. Mappings for - * a bundle's fields should be handled with setFieldMappingConfig. + * a bundle's fields should be handled with setFieldMapping. * * Example usage: * -Map the 'article' bundle to 'sioc:Post'. * @code * rdf_get_mapping('node', 'article') - * ->setBundleMappingConfig(array( + * ->setBundleMapping(array( * 'types' => array('sioc:Post'), * )) * ->save(); @@ -51,10 +61,15 @@ public function getBundleMappingConfig(); * @return \Drupal\rdf\Plugin\Core\Entity\RdfMapping * The RdfMapping object. */ - public function setBundleMappingConfig(array $mapping); + public function setBundleMapping(array $mapping); /** - * Gets the prepared mapping for a field on the bundle. + * Gets the prepared mapping for a field. + * + * The prepared field mapping should be used when outputting data in RDF + * serializations such as RDFa. In the prepared mapping, the mapping + * configuration's CURIE arrays are processed into CURIE strings suitable for + * output. * * @param string $field_name * The name of the field. @@ -62,10 +77,15 @@ public function setBundleMappingConfig(array $mapping); * @return array * The prepared field mapping. */ - public function getFieldMapping($field_name); + public function getPreparedFieldMapping($field_name); /** - * Gets the mapping config for a field on the bundle. + * Gets the mapping config for a field. + * + * This function returns the field mapping as stored in config, which may + * contain CURIE arrays. If the mapping is needed for output in a + * serialization format, such as RDFa, then getPreparedFieldMapping() should + * be used instead. * * @param string $field_name * The name of the field. @@ -73,10 +93,10 @@ public function getFieldMapping($field_name); * @return array|null * The field mapping config array, or NULL if there is no mapping. */ - public function getFieldMappingConfig($field_name); + public function getFieldMapping($field_name); /** - * Sets the mapping configuration for a field. + * Sets the mapping config for a field. * * @param string $field_name * The name of the field. @@ -86,5 +106,5 @@ public function getFieldMappingConfig($field_name); * @return \Drupal\rdf\Plugin\Core\Entity\RdfMapping * The RdfMapping object. */ - public function setFieldMappingConfig($field_name, array $mapping = array()); + public function setFieldMapping($field_name, array $mapping = array()); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php index d366010..8c6319a 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php @@ -55,19 +55,19 @@ public function setUp() { 'properties' => array('sioc:num_replies'), 'datatype' => 'xsd:integer', ); - $article_mapping->setFieldMappingConfig('comment_count', $comment_count_mapping)->save(); + $article_mapping->setFieldMapping('comment_count', $comment_count_mapping)->save(); // Save user mapping. $user_mapping = rdf_get_mapping('user', 'user'); $username_mapping = array( 'properties' => array('foaf:name'), ); - $user_mapping->setFieldMappingConfig('name', $username_mapping)->save(); - $user_mapping->setFieldMappingConfig('homepage', array('properties' => array('foaf:page'), 'mapping_type' => 'rel'))->save(); + $user_mapping->setFieldMapping('name', $username_mapping)->save(); + $user_mapping->setFieldMapping('homepage', array('properties' => array('foaf:page'), 'mapping_type' => 'rel'))->save(); // Save comment mapping. $mapping = rdf_get_mapping('comment', 'comment_node_article'); - $mapping->setBundleMappingConfig(array('types' => array('sioc:Post', 'sioct:Comment')))->save(); + $mapping->setBundleMapping(array('types' => array('sioc:Post', 'sioct:Comment')))->save(); $field_mappings = array( 'title' => array( 'properties' => array('dc:title'), @@ -99,7 +99,7 @@ public function setUp() { ); // Iterate over shared field mappings and save. foreach ($field_mappings as $field_name => $field_mapping) { - $mapping->setFieldMappingConfig($field_name, $field_mapping)->save(); + $mapping->setFieldMapping($field_name, $field_mapping)->save(); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php index 31016d3..06f5d68 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php @@ -55,19 +55,19 @@ function testBundleMapping() { // Test that the bundle mapping can be saved. $types = array('sioc:Post', 'foaf:Document'); rdf_get_mapping($this->entity_type, $this->bundle) - ->setBundleMappingConfig(array('types' => $types)) + ->setBundleMapping(array('types' => $types)) ->save(); $bundle_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getBundleMappingConfig(); + ->getBundleMapping(); $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping saved.'); // Test that the bundle mapping can be edited. $types = array('schema:BlogPosting'); rdf_get_mapping($this->entity_type, $this->bundle) - ->setBundleMappingConfig(array('types' => $types)) + ->setBundleMapping(array('types' => $types)) ->save(); $bundle_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getBundleMappingConfig(); + ->getBundleMapping(); $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping updated.'); } @@ -84,10 +84,10 @@ function testFieldMapping() { 'datatype_callback' => 'date_iso8601', ); rdf_get_mapping($this->entity_type, $this->bundle) - ->setFieldMappingConfig($field_name, $mapping) + ->setFieldMapping($field_name, $mapping) ->save(); $field_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getFieldMappingConfig($field_name); + ->getFieldMapping($field_name); $this->assertEqual($mapping, $field_mapping, 'Field mapping saved.'); // Test that the field mapping can be edited. @@ -97,10 +97,10 @@ function testFieldMapping() { 'datatype_callback' => 'date_iso8601', ); rdf_get_mapping($this->entity_type, $this->bundle) - ->setFieldMappingConfig($field_name, $mapping) + ->setFieldMapping($field_name, $mapping) ->save(); $field_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getFieldMappingConfig($field_name); + ->getFieldMapping($field_name); $this->assertEqual($mapping, $field_mapping, 'Field mapping updated.'); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php index 42a08b8..fda17aa 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php @@ -44,7 +44,7 @@ public function setUp() { // Set the RDF mapping for the new field. $mapping = rdf_get_mapping('node', 'article'); - $mapping->setFieldMappingConfig($this->fieldName, array('properties' => array('rdfs:seeAlso'), 'mapping_type' => 'rel'))->save(); + $mapping->setFieldMapping($this->fieldName, array('properties' => array('rdfs:seeAlso'), 'mapping_type' => 'rel'))->save(); $test_file = $this->getTestFile('text'); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php index 20c028a..f57e4cb 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php @@ -41,7 +41,7 @@ public function setUp() { // Set the RDF mapping for the new field. rdf_get_mapping('node', 'article') - ->setFieldMappingConfig($this->fieldName, array( + ->setFieldMapping($this->fieldName, array( 'properties' => array('og:image'), 'mapping_type' => 'rel', )) diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/NodeAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/NodeAttributesTest.php index 150d736..bf18a63 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/NodeAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/NodeAttributesTest.php @@ -33,13 +33,13 @@ public function setUp() { parent::setUp(); rdf_get_mapping('node', 'article') - ->setBundleMappingConfig(array( + ->setBundleMapping(array( 'types' => array('sioc:Item', 'foaf:Document'), )) - ->setFieldMappingConfig('title', array( + ->setFieldMapping('title', array( 'properties' => array('dc:title'), )) - ->setFieldMappingConfig('created', array( + ->setFieldMapping('created', array( 'properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => 'date_iso8601', diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingUpgradePathTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingUpgradePathTest.php index ac054ca..0474519 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingUpgradePathTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingUpgradePathTest.php @@ -51,21 +51,21 @@ protected function _testUnalteredMappingUpgrade() { $config = rdf_get_mapping('node', 'page'); // Test bundle mapping. - $mapping = $config->getBundleMappingConfig(); + $mapping = $config->getBundleMapping(); $expected_mapping = array( 'types' => array('foaf:Document'), ); $this->assertEqual($mapping, $expected_mapping, 'Unaltered bundle mapping upgraded correctly.'); // Test field mapping - property. - $mapping = $config->getFieldMappingConfig('title'); + $mapping = $config->getFieldMapping('title'); $expected_mapping = array( 'properties' => array('dc:title'), ); $this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping upgraded correctly.'); // Test field mapping - property with datatype and callback. - $mapping = $config->getFieldMappingConfig('created'); + $mapping = $config->getFieldMapping('created'); $expected_mapping = array( 'properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', @@ -74,7 +74,7 @@ protected function _testUnalteredMappingUpgrade() { $this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping with datatype and datatype callback upgraded correctly.'); // Test field mapping - rel. - $mapping = $config->getFieldMappingConfig('uid'); + $mapping = $config->getFieldMapping('uid'); $expected_mapping = array( 'properties' => array('sioc:has_creator'), 'mapping_type' => 'rel', @@ -89,21 +89,21 @@ protected function _testAlteredMappingUpgrade() { $config = rdf_get_mapping('node', 'article'); // Test bundle mapping. - $mapping = $config->getBundleMappingConfig(); + $mapping = $config->getBundleMapping(); $expected_mapping = array( 'types' => array('foo:Type'), ); $this->assertEqual($mapping, $expected_mapping, 'Overriden bundle mapping upgraded correctly.'); // Test field mapping. - $mapping = $config->getFieldMappingConfig('field_image'); + $mapping = $config->getFieldMapping('field_image'); $expected_mapping = array( 'properties' => array('foo:image'), ); $this->assertEqual($expected_mapping, $mapping, 'Overriden field mapping is upgraded correctly.'); // Test field mapping. - $mapping = $config->getFieldMappingConfig('changed'); + $mapping = $config->getFieldMapping('changed'); $expected_mapping = array(); $this->assertEqual($expected_mapping, $mapping, 'Empty field mapping from overriden mapping is upgraded correctly.'); } @@ -114,7 +114,7 @@ protected function _testAlteredMappingUpgrade() { protected function _testReverseRelationUpgrade() { // Test field mapping - rev. $config = rdf_get_mapping('node', 'rev_test'); - $mapping = $config->getFieldMappingConfig('field_rev'); + $mapping = $config->getFieldMapping('field_rev'); $expected_mapping = array(); $this->assertEqual($mapping, $expected_mapping, 'Reverse relation mapping has been dropped.'); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php index 9f3672d..314a4eb 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php @@ -113,7 +113,7 @@ protected function _testAttributes($expected_attributes, $field_mapping, $data = $this->saveMapping($field_mapping); $mapping = rdf_get_mapping('node', 'article') - ->getFieldMapping('field_test'); + ->getPreparedFieldMapping('field_test'); $attributes = rdf_rdfa_attributes($mapping, $data); ksort($expected_attributes); ksort($attributes); @@ -128,7 +128,7 @@ protected function _testAttributes($expected_attributes, $field_mapping, $data = */ protected function saveMapping($field_mapping) { rdf_get_mapping('node', 'article') - ->setFieldMappingConfig('field_test', $field_mapping) + ->setFieldMapping('field_test', $field_mapping) ->save(); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php index fb952f3..99390d3 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php @@ -36,8 +36,8 @@ function setUp() { // RDF mapping - term bundle. rdf_get_mapping('taxonomy_term', $this->vocabulary->id()) - ->setBundleMappingConfig(array('types' => array('skos:Concept'))) - ->setFieldMappingConfig('name', array( + ->setBundleMapping(array('types' => array('skos:Concept'))) + ->setFieldMapping('name', array( 'properties' => array('rdfs:label', 'skos:prefLabel'), )) ->save(); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php index 9ad0ec0..0c7c0cb 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php @@ -46,15 +46,15 @@ public function setUp() { // Set the RDF mapping for the new field. rdf_get_mapping('node', 'article') - ->setFieldMappingConfig($this->fieldName, array( + ->setFieldMapping($this->fieldName, array( 'properties' => array('dc:subject'), 'mapping_type' => 'rel', )) ->save(); rdf_get_mapping('taxonomy_term', $this->vocabulary->id()) - ->setBundleMappingConfig(array('types' => array('skos:Concept'))) - ->setFieldMappingConfig('name', array('properties' => array('rdfs:label'))) + ->setBundleMapping(array('types' => array('skos:Concept'))) + ->setFieldMapping('name', array('properties' => array('rdfs:label'))) ->save(); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php index 2fdbce8..d2d1cdd 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php @@ -76,7 +76,7 @@ function setUp() { ); // Iterate over field mappings and save. foreach ($node_shared_field_mappings as $field_name => $field_mapping) { - $mapping->setFieldMappingConfig($field_name, $field_mapping)->save(); + $mapping->setFieldMapping($field_name, $field_mapping)->save(); } // Enables anonymous posting of content. diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php index 6944c34..8de5927 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/UserAttributesTest.php @@ -32,10 +32,10 @@ public static function getInfo() { public function setUp() { parent::setUp(); rdf_get_mapping('user', 'user') - ->setBundleMappingConfig(array( + ->setBundleMapping(array( 'types' => array('sioc:UserAccount'), )) - ->setFieldMappingConfig('name', array( + ->setFieldMapping('name', array( 'properties' => array('foaf:name'), )) ->save(); diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 1dccf02..07edb4e 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -50,10 +50,10 @@ function rdf_help($path, $arg) { * -Map the 'article' bundle to 'sioc:Post' and the 'title' field to 'dc:title'. * @code * rdf_get_mapping('node', 'article') - * ->setBundleMappingConfig(array( + * ->setBundleMapping(array( * 'types' => array('sioc:Post'), * )) - * ->setFieldMappingConfig('title', array( + * ->setFieldMapping('title', array( * 'properties' => array('dc:title') * )) * ->save(); @@ -201,7 +201,7 @@ function rdf_comment_load($comments) { // isn't needed until rdf_preprocess_comment() is called, but set it here // to optimize performance for websites that implement an entity cache. $created_mapping = rdf_get_mapping('comment', $comment->bundle()) - ->getFieldMapping('created'); + ->getPreparedFieldMapping('created'); $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment->created->value); $comment->rdf_data['nid_uri'] = url('node/' . $comment->nid->target_id); if ($comment->pid->target_id) { @@ -287,7 +287,7 @@ function rdf_preprocess_node(&$variables) { // on.) $bundle = $variables['node']->bundle(); $mapping = rdf_get_mapping('node', $bundle); - $bundle_mapping = $mapping->getBundleMapping('node', $bundle); + $bundle_mapping = $mapping->getPreparedBundleMapping('node', $bundle); $variables['attributes']['about'] = empty($variables['node_url']) ? NULL: $variables['node_url']; $variables['attributes']['typeof'] = empty($bundle_mapping['types']) ? NULL : $bundle_mapping['types']; @@ -295,7 +295,7 @@ function rdf_preprocess_node(&$variables) { // added to the