diff --git a/src/OaiPmh/Metadata/AbstractMetadata.php b/src/OaiPmh/Metadata/AbstractMetadata.php index f6f4784f6d63074dac65fb76458d0c58673593a7..fc1ccd034977befe7dae56b6543a754dd22bea7e 100644 --- a/src/OaiPmh/Metadata/AbstractMetadata.php +++ b/src/OaiPmh/Metadata/AbstractMetadata.php @@ -14,7 +14,11 @@ use OaiPmhRepository\OaiPmh\OaiSet\OaiSetInterface; use OaiPmhRepository\OaiPmh\Plugin\OaiIdentifier; use Omeka\Api\Representation\AbstractResourceEntityRepresentation; use Omeka\Api\Representation\ItemRepresentation; +use Omeka\Api\Representation\ValueRepresentation; use Omeka\Settings\SettingsInterface; +use Zend\EventManager\Event; +use Zend\EventManager\EventManagerAwareInterface; +use Zend\EventManager\EventManagerAwareTrait; /** * Abstract class on which all other metadata format handlers are based. @@ -23,8 +27,12 @@ use Omeka\Settings\SettingsInterface; * @todo Migration to PHP 5.3 will allow the abstract getter functions to be * static, as they should be */ -abstract class AbstractMetadata extends AbstractXmlGenerator implements MetadataInterface +abstract class AbstractMetadata + extends AbstractXmlGenerator + implements MetadataInterface, EventManagerAwareInterface { + use EventManagerAwareTrait; + /** * @var SettingsInterface */ @@ -138,6 +146,34 @@ abstract class AbstractMetadata extends AbstractXmlGenerator implements Metadata } } + /** + * Filter values (remove, update or append) of a resource via an event. + * + * @param AbstractResourceEntityRepresentation $resource + * @param string $term + * @param ValueRepresentation|ValueRepresentation[]|null $values + * @return ValueRepresentation|ValueRepresentation[]|null + */ + protected function filterValues( + AbstractResourceEntityRepresentation $resource, + $term, + $values + ) { + /** @var \Zend\EventManager\EventManager $eventManager */ + $eventManager = $this->getEventManager(); + /** @var \ArrayObject $args */ + $args = $eventManager->prepareArgs([]); + $args['repository'] = self::class; + $args['resource'] = $resource; + $args['term'] = $term; + $args['values'] = $values; + + $event = new Event('oaipmhrepository.values', $this, $args); + $eventManager->triggerEvent($event); + + return $args['values']; + } + /** * Appends a metadata element, a child element with the required format, and * further children for each of the properties present in the item.