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 0f772ff..b54a38e 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 @@ -10,6 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; +use Drupal\rdf\RdfMappingInterface; /** * Config entity for working with RDF mappings. @@ -28,7 +29,7 @@ * } * ) */ -class RdfMapping extends ConfigEntityBase { +class RdfMapping extends ConfigEntityBase implements RdfMappingInterface { /** * Unique ID for the config entity. @@ -73,10 +74,7 @@ class RdfMapping extends ConfigEntityBase { protected $fieldMappings; /** - * Gets the mapping for the bundle-level data. - * - * @return array|null - * The field mapping, or NULL if there is no mapping. + * {@inheritdoc} */ public function getBundleMapping() { $types = array(); @@ -87,28 +85,19 @@ public function getBundleMapping() { } /** - * Sets the mapping for a bundle. - * - * This only sets bundle-level mappings, such as the RDF type. Mappings for - * a bundle's fields should be handled with setFieldMapping. - * - * Example usage: - * -Map the 'article' bundle to 'sioc:Post'. - * @code - * rdf_get_mapping('node', 'article') - * ->setBundleMapping(array( - * 'types' => array('sioc:Post'), - * )) - * ->save(); - * @endcode - * - * @param array $mapping - * The bundle mapping. - * - * @return \Drupal\rdf\Plugin\Core\Entity\RdfMapping - * The RdfMapping object. + * {@inheritdoc} + */ + public function getBundleMappingConfig() { + if (isset($this->types)) { + return array('types' => $this->types); + } + return NULL; + } + + /** + * {@inheritdoc} */ - public function setBundleMapping(array $mapping) { + public function setBundleMappingConfig(array $mapping) { if (isset($mapping['types'])) { $this->types = $mapping['types']; } @@ -117,13 +106,7 @@ public function setBundleMapping(array $mapping) { } /** - * Gets the mapping for a field on the bundle. - * - * @param string $field_name - * The name of the field. - * - * @return array|null - * The field mapping, or NULL if there is no mapping. + * {@inheritdoc} */ public function getFieldMapping($field_name) { $field_mapping = array( @@ -139,17 +122,19 @@ public function getFieldMapping($field_name) { } /** - * Sets the mapping for a field. - * - * @param string $field_name - * The name of the field. - * @param array $mapping - * The field mapping. - * - * @return \Drupal\rdf\Plugin\Core\Entity\RdfMapping - * The RdfMapping object. + * {@inheritdoc} + */ + public function getFieldMappingConfig($field_name) { + if (isset($this->fieldMappings[$field_name])) { + return $this->fieldMappings[$field_name]; + } + return NULL; + } + + /** + * {@inheritdoc} */ - public function setFieldMapping($field_name, array $mapping = array()) { + public function setFieldMappingConfig($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 new file mode 100644 index 0000000..21ab065 --- /dev/null +++ b/core/modules/rdf/lib/Drupal/rdf/RdfMappingInterface.php @@ -0,0 +1,90 @@ +setBundleMappingConfig(array( + * 'types' => array('sioc:Post'), + * )) + * ->save(); + * @endcode + * + * @param array $mapping + * The bundle mapping. + * + * @return \Drupal\rdf\Plugin\Core\Entity\RdfMapping + * The RdfMapping object. + */ + public function setBundleMappingConfig(array $mapping); + + /** + * Gets the prepared mapping for a field on the bundle. + * + * @param string $field_name + * The name of the field. + * + * @return array + * The prepared field mapping. + */ + public function getFieldMapping($field_name); + + /** + * Gets the mapping config for a field on the bundle. + * + * @param string $field_name + * The name of the field. + * + * @return array|null + * The field mapping config array, or NULL if there is no mapping. + */ + public function getFieldMappingConfig($field_name); + + /** + * Sets the mapping configuration for a field. + * + * @param string $field_name + * The name of the field. + * @param array $mapping + * The field mapping. + * + * @return \Drupal\rdf\Plugin\Core\Entity\RdfMapping + * The RdfMapping object. + */ + public function setFieldMappingConfig($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 e3e5c22..c596c1f 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->setFieldMapping('comment_count', $comment_count_mapping)->save(); + $article_mapping->setFieldMappingConfig('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->setFieldMapping('name', $username_mapping)->save(); - $user_mapping->setFieldMapping('homepage', array('properties' => array('foaf:page'), 'mapping_type' => 'rel'))->save(); + $user_mapping->setFieldMappingConfig('name', $username_mapping)->save(); + $user_mapping->setFieldMappingConfig('homepage', array('properties' => array('foaf:page'), 'mapping_type' => 'rel'))->save(); // Save comment mapping. $mapping = rdf_get_mapping('comment', 'comment_node_article'); - $mapping->setBundleMapping(array('types' => array('sioc:Post', 'sioct:Comment')))->save(); + $mapping->setBundleMappingConfig(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->setFieldMapping($field_name, $field_mapping)->save(); + $mapping->setFieldMappingConfig($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 e179458..31016d3 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) - ->setBundleMapping(array('types' => $types)) + ->setBundleMappingConfig(array('types' => $types)) ->save(); $bundle_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getBundleMapping(); + ->getBundleMappingConfig(); $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) - ->setBundleMapping(array('types' => $types)) + ->setBundleMappingConfig(array('types' => $types)) ->save(); $bundle_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getBundleMapping(); + ->getBundleMappingConfig(); $this->assertEqual($types, $bundle_mapping['types'], 'Bundle mapping updated.'); } @@ -84,12 +84,11 @@ function testFieldMapping() { 'datatype_callback' => 'date_iso8601', ); rdf_get_mapping($this->entity_type, $this->bundle) - ->setFieldMapping($field_name, $mapping) + ->setFieldMappingConfig($field_name, $mapping) ->save(); $field_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getFieldMapping($field_name); - $intersection = array_intersect_key($field_mapping, $mapping); - $this->assertEqual($mapping, $intersection, 'Field mapping saved.'); + ->getFieldMappingConfig($field_name); + $this->assertEqual($mapping, $field_mapping, 'Field mapping saved.'); // Test that the field mapping can be edited. $mapping = array( @@ -98,11 +97,10 @@ function testFieldMapping() { 'datatype_callback' => 'date_iso8601', ); rdf_get_mapping($this->entity_type, $this->bundle) - ->setFieldMapping($field_name, $mapping) + ->setFieldMappingConfig($field_name, $mapping) ->save(); $field_mapping = rdf_get_mapping($this->entity_type, $this->bundle) - ->getFieldMapping($field_name); - $intersection = array_intersect_key($field_mapping, $mapping); - $this->assertEqual($mapping, $intersection, 'Field mapping updated.'); + ->getFieldMappingConfig($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 773b6c3..c12588d 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->setFieldMapping($this->fieldName, array('properties' => array('rdfs:seeAlso'), 'mapping_type' => 'rel'))->save(); + $mapping->setFieldMappingConfig($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 546fae5..816f9ea 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') - ->setFieldMapping($this->fieldName, array( + ->setFieldMappingConfig($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 bf18a63..150d736 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') - ->setBundleMapping(array( + ->setBundleMappingConfig(array( 'types' => array('sioc:Item', 'foaf:Document'), )) - ->setFieldMapping('title', array( + ->setFieldMappingConfig('title', array( 'properties' => array('dc:title'), )) - ->setFieldMapping('created', array( + ->setFieldMappingConfig('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 1891c23..ac054ca 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingUpgradePathTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingUpgradePathTest.php @@ -51,34 +51,34 @@ protected function _testUnalteredMappingUpgrade() { $config = rdf_get_mapping('node', 'page'); // Test bundle mapping. - $mapping = $config->getBundleMapping(); + $mapping = $config->getBundleMappingConfig(); $expected_mapping = array( 'types' => array('foaf:Document'), ); $this->assertEqual($mapping, $expected_mapping, 'Unaltered bundle mapping upgraded correctly.'); // Test field mapping - property. - $mapping = $config->getFieldMapping('title'); - $expected_mapping = $this->prepareExpectedFieldMapping(array( + $mapping = $config->getFieldMappingConfig('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->getFieldMapping('created'); - $expected_mapping = $this->prepareExpectedFieldMapping(array( + $mapping = $config->getFieldMappingConfig('created'); + $expected_mapping = array( 'properties' => array('dc:date', 'dc:created'), 'datatype' => 'xsd:dateTime', 'datatype_callback' => 'date_iso8601', - )); + ); $this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping with datatype and datatype callback upgraded correctly.'); // Test field mapping - rel. - $mapping = $config->getFieldMapping('uid'); - $expected_mapping = $this->prepareExpectedFieldMapping(array( + $mapping = $config->getFieldMappingConfig('uid'); + $expected_mapping = array( 'properties' => array('sioc:has_creator'), 'mapping_type' => 'rel', - )); + ); $this->assertEqual($mapping, $expected_mapping, 'Unaltered field mapping with rel mapping type upgraded correctly.'); } @@ -89,22 +89,22 @@ protected function _testAlteredMappingUpgrade() { $config = rdf_get_mapping('node', 'article'); // Test bundle mapping. - $mapping = $config->getBundleMapping(); + $mapping = $config->getBundleMappingConfig(); $expected_mapping = array( 'types' => array('foo:Type'), ); $this->assertEqual($mapping, $expected_mapping, 'Overriden bundle mapping upgraded correctly.'); // Test field mapping. - $mapping = $config->getFieldMapping('field_image'); - $expected_mapping = $this->prepareExpectedFieldMapping(array( + $mapping = $config->getFieldMappingConfig('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->getFieldMapping('changed'); - $expected_mapping = $this->prepareExpectedFieldMapping(array()); + $mapping = $config->getFieldMappingConfig('changed'); + $expected_mapping = array(); $this->assertEqual($expected_mapping, $mapping, 'Empty field mapping from overriden mapping is upgraded correctly.'); } @@ -114,28 +114,9 @@ protected function _testAlteredMappingUpgrade() { protected function _testReverseRelationUpgrade() { // Test field mapping - rev. $config = rdf_get_mapping('node', 'rev_test'); - $mapping = $config->getFieldMapping('field_rev'); - $expected_mapping = $this->prepareExpectedFieldMapping(array()); + $mapping = $config->getFieldMappingConfig('field_rev'); + $expected_mapping = array(); $this->assertEqual($mapping, $expected_mapping, 'Reverse relation mapping has been dropped.'); } - /** - * Prepares the expected mapping array with default values. - * - * @param array $mapping - * The significant values of the expected mapping. - * - * @return array - * The full mapping array, including default values. - */ - protected function prepareExpectedFieldMapping($mapping) { - $default_mapping = array( - 'properties' => NULL, - 'datatype' => NULL, - 'datatype_callback' => NULL, - 'mapping_type' => NULL, - ); - return array_merge($default_mapping, $mapping); - } - } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php index 7dc2345..9f3672d 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaAttributesTest.php @@ -128,7 +128,7 @@ protected function _testAttributes($expected_attributes, $field_mapping, $data = */ protected function saveMapping($field_mapping) { rdf_get_mapping('node', 'article') - ->setFieldMapping('field_test', $field_mapping) + ->setFieldMappingConfig('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 99390d3..fb952f3 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()) - ->setBundleMapping(array('types' => array('skos:Concept'))) - ->setFieldMapping('name', array( + ->setBundleMappingConfig(array('types' => array('skos:Concept'))) + ->setFieldMappingConfig('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 0c7c0cb..9ad0ec0 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') - ->setFieldMapping($this->fieldName, array( + ->setFieldMappingConfig($this->fieldName, array( 'properties' => array('dc:subject'), 'mapping_type' => 'rel', )) ->save(); rdf_get_mapping('taxonomy_term', $this->vocabulary->id()) - ->setBundleMapping(array('types' => array('skos:Concept'))) - ->setFieldMapping('name', array('properties' => array('rdfs:label'))) + ->setBundleMappingConfig(array('types' => array('skos:Concept'))) + ->setFieldMappingConfig('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 d2d1cdd..2fdbce8 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->setFieldMapping($field_name, $field_mapping)->save(); + $mapping->setFieldMappingConfig($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 8de5927..6944c34 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') - ->setBundleMapping(array( + ->setBundleMappingConfig(array( 'types' => array('sioc:UserAccount'), )) - ->setFieldMapping('name', array( + ->setFieldMappingConfig('name', array( 'properties' => array('foaf:name'), )) ->save(); diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 890bcd6..107dce7 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') - * ->setBundleMapping(array( + * ->setBundleMappingConfig(array( * 'types' => array('sioc:Post'), * )) - * ->setFieldMapping('title', array( + * ->setFieldMappingConfig('title', array( * 'properties' => array('dc:title') * )) * ->save();