From 34311dca5f44c842d945d43d1a67fb980c22f708 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 28 Aug 2025 12:42:54 +0300 Subject: [PATCH 1/3] Update CustomVocabRepresentation.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added the ability to add values ​​with labels, separating them = --- .../Representation/CustomVocabRepresentation.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Api/Representation/CustomVocabRepresentation.php b/src/Api/Representation/CustomVocabRepresentation.php index 83fb585..3aa7ed6 100644 --- a/src/Api/Representation/CustomVocabRepresentation.php +++ b/src/Api/Representation/CustomVocabRepresentation.php @@ -152,13 +152,21 @@ public function listItemTitles(array $options = []): ?array /** * List of terms by term when the vocab is a simple list. + * If you need to add values ​​with labels, you need to separate them = */ public function listTerms(): ?array { $terms = $this->resource->getTerms(); - return $terms - ? array_combine($terms, $terms) - : null; + $rc = []; + foreach($terms as $v){ + if(stripos($v, '=') !== False){ + $nval = explode('=', $v); + $rc[trim($nval[0])] = trim($nval[1]); + }else{ + $rc[$v] = $v; + } + } + return $rc; } /** From 20ecef2fcbcc96afc95ebc305d6936d5a2ac0416 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 28 Aug 2025 13:05:17 +0300 Subject: [PATCH 2/3] Update Module.php Added auto-replace value with its name if available --- Module.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Module.php b/Module.php index eeda30e..3aed89b 100644 --- a/Module.php +++ b/Module.php @@ -179,6 +179,14 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager) 'data_types.value_annotating', [$this, 'addDataTypesToValueAnnotatingConfig'] ); + + $sharedEventManager->attach( + \Omeka\Api\Representation\ValueRepresentation::class, + 'rep.value.html', + [$this, 'handleRepresentationValueHtml'], + -1000 + ); + } public function addVocabularyServices(Event $event) @@ -256,4 +264,47 @@ public function addDataTypesToValueAnnotatingConfig(Event $event) } $event->setParam('data_types', $valueAnnotating); } + + /** + * Convert selected property values to its title. + * + * @todo Factorize handleRepresentationValueHtml(). + * + */ + public function handleRepresentationValueHtml(Event $event): void + { + + $services = $this->getServiceLocator(); + $status = $services->get('Omeka\Status'); + $apiManager = $services->get('Omeka\ApiManager'); + $isSite = $status->isSiteRequest(); + $isAdmin = $status->isAdminRequest(); + if (!$isSite && !$isAdmin) { + return; + } + $value = $event->getTarget(); + $type = $value->type(); + if(!empty($type) && stripos($type, 'customvocab') !== False){ + $rc = explode(':', $type); + if(!empty($rc[1])){ + $customvocabID = $rc[1]; + $response = $apiManager->read('custom_vocabs', $customvocabID); + if(!empty($response)){ + $listValues = $response->getContent()->listValues(); + $val = (string) $value->value(); + if(!empty($listValues) && !empty($val) && !empty($listValues[$val])){ + $html = $event->getParam('html'); + $need[] = '/'.$val.'/i';; + $need[] = '/(>.+<\/a>)/i'; + $replace[] = $listValues[$val]; + $replace[] = '>'.$listValues[$val].''; + $html = preg_replace($need, $replace, $html); + $event->setParam('html', $html); + } + } + } + } + + } + } From 38c69b22dc352e120bda57bc157775ef8efded74 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 28 Aug 2025 16:14:58 +0300 Subject: [PATCH 3/3] Update Module.php Fixed and checked compatibility with value to link conversion of the following modules: Advanced Resource Template 3.4.43 Metadata Browse 1.6.0 --- Module.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Module.php b/Module.php index 3aed89b..af3578c 100644 --- a/Module.php +++ b/Module.php @@ -270,6 +270,11 @@ public function addDataTypesToValueAnnotatingConfig(Event $event) * * @todo Factorize handleRepresentationValueHtml(). * + * Compatible with the converted value to a link of the following modules: + * + * Advanced Resource Template 3.4.43 + * Metadata Browse 1.6.0 + * */ public function handleRepresentationValueHtml(Event $event): void { @@ -294,10 +299,13 @@ public function handleRepresentationValueHtml(Event $event): void $val = (string) $value->value(); if(!empty($listValues) && !empty($val) && !empty($listValues[$val])){ $html = $event->getParam('html'); - $need[] = '/'.$val.'/i';; - $need[] = '/(>.+<\/a>)/i'; - $replace[] = $listValues[$val]; - $replace[] = '>'.$listValues[$val].''; + if(stripos($html, '') !== False){ + $need[] = '/(>.+<\/a>)/i'; + $replace[] = '>'.$listValues[$val].''; + }else{ + $need[] = '/'.$val.'/i'; + $replace[] = $listValues[$val]; + } $html = preg_replace($need, $replace, $html); $event->setParam('html', $html); }