From 163fd9d27381df3b2b92ad54e0cf7801571d2379 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 7 Sep 2018 08:32:27 -0300 Subject: [PATCH] Add way to filter hook on content model. --- includes/orphaned_objects.inc | 2 +- islandora.api.php | 33 +++++++++++++++++++++------------ islandora.module | 4 +++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/includes/orphaned_objects.inc b/includes/orphaned_objects.inc index 1d90b4d7..7393971d 100644 --- a/includes/orphaned_objects.inc +++ b/includes/orphaned_objects.inc @@ -169,7 +169,7 @@ WHERE { FILTER (!bound(?liveparent)) } ORDER BY ?object EOQ; - $parent_relationships = module_invoke_all('islandora_solution_pack_child_relationships'); + $parent_relationships = module_invoke_all('islandora_solution_pack_child_relationships', 'all'); if (count($parent_relationships['predicate']) == 0) { // No predicates to search for. Exit early. return array(); diff --git a/islandora.api.php b/islandora.api.php index 166998ac..c2d391e6 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -970,17 +970,26 @@ function hook_islandora_datastream_filename_alter(&$filename, AbstractDatastream /** * Allow solution packs to register relationships used for children. * + * @param string|array $cmodels + * This takes either: + * - string: the string 'all'. Function returns all child relationships. + * - array: an array of cmodel PIDs to return the relationships for. + * * @return array - * - prefix (array): This is is a valid snip-it of SPARQL to register prefixes used in the predicates array. - * - predicate (array): This array contains predicates used by the solution pack for child objects. - */ -function hook_islandora_solution_pack_child_relationships() { - return array( - 'prefix' => array('PREFIX islandora: '), - 'predicate' => array( - '', - '', - '', - ), - ); + * - prefix (array): This is is a valid snip-it of SPARQL to register + * prefixes used in the predicates array. + * - predicate (array): This array contains predicates used by the solution + * pack for child objects. + */ +function hook_islandora_solution_pack_child_relationships($cmodels) { + if ($cmodels === 'all' or in_array('my:cmodel_pid', $cmodels)) { + return array( + 'prefix' => array('PREFIX islandora: '), + 'predicate' => array( + '', + '', + '', + ), + ); + } } \ No newline at end of file diff --git a/islandora.module b/islandora.module index effa4a79..bbce6d1e 100644 --- a/islandora.module +++ b/islandora.module @@ -2219,6 +2219,8 @@ function islandora_islandora_breadcrumbs_backends() { /** * Implements hook_islandora_solution_pack_child_relationships */ -function islandora_islandora_solution_pack_child_relationships() { +function islandora_islandora_solution_pack_child_relationships($cmodels) { + // Return empty arrays from core implementation so that these keys always + // exist when the hook is called, even if no module responds. return array('predicate' => array(), 'prefix' => array()); } \ No newline at end of file