I’ve been trying to address this issue with a plugin that uses hookBeforeSaveItem. I’ve figured out how to add the address from geolocation into a DC element, but I don’t understand how to delete or replace existing element texts for that element. Here’s what I have so far:
?php
class GeoToCoveragePlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array('before_save_item');
public function hookBeforeSaveItem($args)
{
if (!($post = $args['post'])) {
return;
}
$item = $args['record'];
// If we don't have the geolocation form on the page, don't do anything!
if (!isset($post['geolocation'])) {
return;
}
$geolocationPost = $post['geolocation'];
$db = get_db();
$elementTable = $db->getTable('Element');
$coverageElement = $elementTable->findByElementSetNameAndElementName('Dublin Core', 'Subject');
if (!empty($geolocationPost)
&& $geolocationPost['latitude'] != ''
&& $geolocationPost['longitude'] != ''
&& $geolocationPost['address'] != ''
) {
//This next line doesn't actually delete element texts
$item->deleteElementTextsByElementId(array($coverageElement->id));
//This next line DOES add the address from post into the DC field
$item->addTextForElement($coverageElement, $geolocationPost['address']);
} else {
//Still need to complete this
}
}
}
}
?>
Any help would be much appreciated.