Skip to content

Commit

Permalink
cwrc#6: Enable Solr search formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ctgraham committed Feb 1, 2023
1 parent ad60099 commit 2600254
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
25 changes: 24 additions & 1 deletion islandora_object_field.module
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@ function islandora_object_field_field_is_empty($item, $field) {
* Implements hook_field_formatter_info().
*/
function islandora_object_field_field_formatter_info() {
return array(
$formatters = array(
'islandora_object_field_label_formatter' => array(
'label' => t('Object label'),
'field types' => array('islandora_object_field'),
),
);
if (module_exists('islandora_solr')) {
$formatters['islandora_object_field_solr_formatter'] = array(
'label' => t('Solr search'),
'field types' => array('islandora_object_field'),
);
}
return $formatters;
}

/**
Expand All @@ -150,6 +157,7 @@ function islandora_object_field_field_formatter_view($entity_type, $entity, $fie

switch ($display['type']) {
case 'islandora_object_field_label_formatter':
case 'islandora_object_field_solr_formatter':
foreach ($items as $delta => $item) {
try {
$object = $repository->getObject($item['pid']);
Expand All @@ -159,6 +167,17 @@ function islandora_object_field_field_formatter_view($entity_type, $entity, $fie
'#pid' => $item['pid'],
'#label' => $object->label,
);
// Solr formatter adds a rendered Solr search result
if ($display['type'] == 'islandora_object_field_solr_formatter' && module_exists('islandora_solr')) {
drupal_load('module', 'islandora_solr');
$query = format_string('!field:!value', array('!field' => 'PID', '!value' => islandora_solr_lesser_escape($item['pid'])));
$qp = new IslandoraSolrQueryProcessor();
$qp->buildQuery($query);
$qp->executeQuery();
$results = new IslandoraSolrResults();
$solr = $results->printResults($qp->islandoraSolrResult);
$element[$delta]['#solr'] = $solr;
}
}
catch (Exception $e) {
// This is likely a permissions issue, continue on.
Expand All @@ -179,6 +198,10 @@ function islandora_object_field_theme($existing, $type, $theme, $path) {
'template' => 'templates/islandora-object-field-label',
'variables' => array('label' => NULL, 'pid' => NULL, 'object' => NULL),
),
'islandora_object_field_solr' => array(
'template' => 'templates/islandora-object-field-solr',
'variables' => array('label' => NULL, 'pid' => NULL, 'object' => NULL, 'solr' => NULL),
),
);
}

Expand Down
1 change: 1 addition & 0 deletions templates/islandora-object-field-label.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
* Available variables:
* - $label: The label text.
* - $object: The Fedora object
* - $pid: The ID of the object whose label is being displayed.
*/
echo l($label, 'islandora/object/' . $pid); ?>
18 changes: 18 additions & 0 deletions templates/islandora-object-field-solr.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* @file
* Displays an Islandora object as a Solr search result
*
* Available variables:
* - $label: The label text.
* - $object: The Fedora object
* - $pid: The ID of the object whose label is being displayed.
* - $solr: The rendered solr search result for the object
*/
?>
<div class="islandora-object-field-wrapper">
<?php
echo $solr;
?>
</div>

0 comments on commit 2600254

Please sign in to comment.