diff --git a/model/ConceptProperty.php b/model/ConceptProperty.php index 83041e33d..99ff7f6b6 100644 --- a/model/ConceptProperty.php +++ b/model/ConceptProperty.php @@ -61,6 +61,14 @@ public function getLabel() return null; } + /** + * Returns an alphanumeric ID for the property, suitable for use as a CSS identifier. + */ + public function getID() + { + return preg_replace('/[^A-Za-z0-9-]/', '_', $this->prop); + } + /** * Returns text for the property tooltip. * @return string diff --git a/resource/js/scripts.js b/resource/js/scripts.js index 7f5eeac3a..723e422a2 100644 --- a/resource/js/scripts.js +++ b/resource/js/scripts.js @@ -433,6 +433,7 @@ function loadMappingProperties(concept, lang, contentLang, $htmlElement, concept if (!found) { conceptProperty = { 'type': conceptMappingPropertyValue.type[0], + 'id': conceptMappingPropertyValue.type[0].replace(/[^A-Za-z-]/g, '_'), 'label': conceptMappingPropertyValue.typeLabel, 'notation': conceptMappingPropertyValue.notation, 'description': conceptMappingPropertyValue.description, diff --git a/tests/ConceptPropertyTest.php b/tests/ConceptPropertyTest.php index e2cfbd4f0..fe2ac300b 100644 --- a/tests/ConceptPropertyTest.php +++ b/tests/ConceptPropertyTest.php @@ -147,4 +147,23 @@ public function testGetPropertiesSubClassOfHiddenLabel() $props = $concept->getProperties(); $this->assertEquals('skos:hiddenLabel', $props['subclass:prop1']->getSubPropertyOf()); } + + /** + * @covers ConceptProperty::getID + */ + public function testGetIDShortenedURI() + { + $prop = new ConceptProperty('skosmos:testLabel', 'Test label'); + $this->assertEquals('skosmos_testLabel', $prop->getID()); + } + + /** + * @covers ConceptProperty::getID + */ + public function testGetIDFullURI() + { + $prop = new ConceptProperty('http://rdaregistry.info/Elements/a/P50008', 'has hierarchical superior'); + $this->assertEquals('http___rdaregistry_info_Elements_a_P50008', $prop->getID()); + } + } diff --git a/view/concept-shared.twig b/view/concept-shared.twig index 6b80a87c8..9e2b37d5a 100644 --- a/view/concept-shared.twig +++ b/view/concept-shared.twig @@ -39,7 +39,7 @@ {% endif %} {% spaceless %} -