Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -256,4 +264,55 @@ public function addDataTypesToValueAnnotatingConfig(Event $event)
}
$event->setParam('data_types', $valueAnnotating);
}

/**
* Convert selected property values to its title.
*
* @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
{

$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');
if(stripos($html, '</a>') !== False){
$need[] = '/(>.+<\/a>)/i';
$replace[] = '>'.$listValues[$val].'</a>';
}else{
$need[] = '/'.$val.'/i';
$replace[] = $listValues[$val];
}
$html = preg_replace($need, $replace, $html);
$event->setParam('html', $html);
}
}
}
}

}

}
14 changes: 11 additions & 3 deletions src/Api/Representation/CustomVocabRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down