Skip to content

Instantly share code, notes, and snippets.

@patrickmj
Created March 17, 2014 19:09
Show Gist options
  • Save patrickmj/9606140 to your computer and use it in GitHub Desktop.
Save patrickmj/9606140 to your computer and use it in GitHub Desktop.
Required Metadata for Omeka plugin work
<?php
class RequiredMetadataPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array('before_save_item');
protected $_filters = array(
'itemTitleLengthValidator' => array('Validate', 'Item', 'Dublin Core', 'Title'),
);
public function hookBeforeSaveItem($args)
{
$item = $args['record'];
$title = metadata($item, array('Dublin Core', 'Title'));
if(empty($title)) {
$item->addError("DC Title", 'DC Title cannot be empty!');
}
}
public function itemTitleLengthValidator($isValid, $args)
{
$record = $args['record'];
$text = $args['text'];
if(strlen($text) < 10 ) {
$record->addError('DC Title Length', 'DC Title is Too Short!');
return false;
}
return true;
}
}
@patrickmj
Copy link
Author

The first param to addError will always have a unique value, so repeated us of 'Title' there will clobber later usage. It doesn't come out especially pretty on the admin side, but it might do the job, to just use more descriptive text instead of the real field name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment