Created
March 17, 2014 19:09
-
-
Save patrickmj/9606140 to your computer and use it in GitHub Desktop.
Required Metadata for Omeka plugin work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.