Skip to content

Commit

Permalink
Fix browse views and usage of lang filtering
Browse files Browse the repository at this point in the history
This fixes two related issues: first, a regression from 4.0 for the
default browse views: when moving them to use linkPretty to avoid
redundant links, the logic for choosing different title properties and
langauges was broken. This keeps the linkPretty markup structure but
restores the browse heading property and lang filtering features.

Second, this harmonizes treatment of filter_locale_values across the
site views. Throughout, all usages pass the configured lang plus the
empty string which allows values with unset langs to pass the filter;
this matches with the pre-4.0 browse page behavior and the previous and
continuing behavior of the resource-values view.

Together, these also result in fixing media show to respect
filter_locale_values, and fixing the browse-preview block markup to
properly match the normal browse markup.

(fix #1996)
  • Loading branch information
zerocrates committed Feb 14, 2023
1 parent a602d22 commit 4753f8e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion application/view/common/advanced-search/item-sets.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if ($this->status()->isSiteRequest()) {
$selectOptions = [
'disable_group_by_owner' => true,
'query' => ['site_id' => $this->layout()->site->id()],
'lang' => ($filterLocale == 1 ? $lang : null)
'lang' => $filterLocale ? [$lang, ''] : null
];
} else {
$selectOptions = [];
Expand Down
23 changes: 14 additions & 9 deletions application/view/common/block-layout/browse-preview.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$thumbnail = $this->plugin('thumbnail');
?>
<div class="preview-block">

Expand All @@ -18,21 +19,25 @@ $bodyTerm = $this->siteSetting('browse_body_property_term');

$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;

foreach ($this->resources as $resource):
$heading = $headingTerm ? $resource->value($headingTerm, ['default' => $translate('[Untitled]')]) : $resource->displayTitle(null, ($filterLocale ? $lang : null));
$body = $bodyTerm ? $resource->value($bodyTerm) : $resource->displayDescription(null, ($filterLocale ? $lang : null));
$thumbnail = $this->thumbnail($resource, 'medium', ['title' => $heading]);
$heading = $headingTerm ? $resource->value($headingTerm, ['default' => $translate('[Untitled]'), 'lang' => $valueLang]) : $resource->displayTitle(null, $valueLang);
$body = $bodyTerm ? $resource->value($bodyTerm, ['lang' => $valueLang]) : $resource->displayDescription(null, $valueLang);
?>
<li class="<?php echo $this->resourceType; ?> resource">
<?php
if ($showThumbnail && $thumbnail):
echo $resource->linkRaw($thumbnail);
endif;?>
<?php
$linkContent = '';
if ($showThumbnail):
$linkContent .= $this->thumbnail($resource, 'medium');
endif;
if ($showHeading):
echo '<h4>' . $resource->link($heading) . '</h4>';
endif;?>
$linkContent .= '<span class="resource-name">' . $escape($heading) . '</span>';
endif;
if ($linkContent !== '') {
echo $resource->linkRaw($linkContent, null, ['class' => 'resource-link']);
}
?>
<?php if ($showBody && $body): ?>
<div class="description"><?php echo $escape($body); ?></div>
<?php endif; ?>
Expand Down
6 changes: 3 additions & 3 deletions application/view/common/linked-resources.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ $fragment = 'resources-linked';
$pagination->setFragment($fragment);

// Set up locale.
$lang = null;
$filterLocale = false;
$valueLang = null;
if ($this->status()->isSiteRequest()) {
$lang = $this->lang();
$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$valueLang = $filterLocale ? [$lang, ''] : null;
}

// Set up resource property select.
Expand Down Expand Up @@ -78,7 +78,7 @@ $caption = sprintf(
<tbody>
<?php foreach ($values as $value): ?>
<tr class="linked-resource">
<td><?php echo $value['val']->resource()->linkPretty('square', null, null, null, ($filterLocale ? $lang : null)); ?></td>
<td><?php echo $value['val']->resource()->linkPretty('square', null, null, null, $valueLang); ?></td>
<td>
<?php if ($value['val']->resource()->resourceClass()): ?>
<span class="resource-class"><?php echo $this->escapeHtml($this->translate($value['val']->resource()->resourceClass()->label())); ?></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;
?>
<?php if ($itemSets): ?>
<dl class="item-sets">
<div class="property">
<dt><?php echo $this->translate('Item sets'); ?></dt>
<?php foreach ($itemSets as $itemSet): ?>
<dd class="value">
<a href="<?php echo $this->escapeHtml($itemSet->url()); ?>"><?php echo $itemSet->displayTitle(null, ($filterLocale ? $this->lang() : null)); ?></a>
<a href="<?php echo $this->escapeHtml($itemSet->url()); ?>"><?php echo $itemSet->displayTitle(null, $valueLang); ?></a>
</dd>
<?php endforeach; ?>
</div>
Expand Down
5 changes: 3 additions & 2 deletions application/view/omeka/site/index/search.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $this->htmlElement('body')->appendAttribute('class', 'index search');

$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;
?>

<?php echo $this->pageTitle(sprintf($translate('Search results for “%s”'), $query)); ?>
Expand Down Expand Up @@ -38,11 +39,11 @@ $resourceControllers = [
<?php if ($resourceName === 'site_pages') {
echo $resource->link($resource->title());
} else {
echo $resource->link($resource->displayTitle(null, ($filterLocale ? $lang : null)));
echo $resource->link($resource->displayTitle(null, $valueLang));
}
?>
<?php else: ?>
<?php echo $resource->linkPretty('square', null, null, null, ($filterLocale ? $lang : null)); ?>
<?php echo $resource->linkPretty('square', null, null, null, $valueLang); ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
Expand Down
13 changes: 10 additions & 3 deletions application/view/omeka/site/item-set/browse.phtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$thumbnail = $this->plugin('thumbnail');

$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;

$this->htmlElement('body')->appendAttribute('class', 'item-set resource browse');
?>
Expand All @@ -23,11 +25,16 @@ $this->htmlElement('body')->appendAttribute('class', 'item-set resource browse')
$headingTerm = $this->siteSetting('browse_heading_property_term');
$bodyTerm = $this->siteSetting('browse_body_property_term');
foreach ($itemSets as $itemSet):
$heading = $headingTerm ? $itemSet->value($headingTerm, ['default' => $translate('[Untitled]'), 'lang' => ($filterLocale ? [$lang, ''] : null)]) : $itemSet->displayTitle(null, ($filterLocale ? [$lang, ''] : null));
$body = $bodyTerm ? $itemSet->value($bodyTerm, ['lang' => ($filterLocale ? [$lang, ''] : null)]) : $itemSet->displayDescription(null, ($filterLocale ? [$lang, ''] : null));
$heading = $headingTerm ? $itemSet->value($headingTerm, ['default' => $translate('[Untitled]'), 'lang' => $valueLang]) : $itemSet->displayTitle(null, $valueLang);
$body = $bodyTerm ? $itemSet->value($bodyTerm, ['lang' => $valueLang]) : $itemSet->displayDescription(null, $valueLang);
?>
<li class="item-set resource">
<?php echo $itemSet->linkPretty('medium', $heading); ?>
<?php
$linkContent = sprintf('%s<span class="resource-name">%s</span>',
$thumbnail($itemSet, 'medium'),
$escape($heading));
echo $itemSet->linkRaw($linkContent, null, ['class' => 'resource-link']);
?>
<?php if ($body): ?>
<div class="description"><?php echo $escape($body); ?></div>
<?php endif; ?>
Expand Down
15 changes: 11 additions & 4 deletions application/view/omeka/site/item/browse.phtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$thumbnail = $this->plugin('thumbnail');
$this->htmlElement('body')->appendAttribute('class', 'item resource browse');

$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;

$query = $this->params()->fromQuery();
$itemSetShow = isset($itemSet);
Expand All @@ -16,7 +18,7 @@ endif;
?>

<?php if ($itemSetShow): ?>
<?php echo $this->pageTitle($itemSet->displayTitle(null, ($filterLocale ? $lang : null)), 2); ?>
<?php echo $this->pageTitle($itemSet->displayTitle(null, $valueLang), 2); ?>
<h3><?php echo $translate('Item set'); ?></h3>
<div class="metadata">
<?php echo $this->resourcePageBlocks($itemSet)->getBlocks(); ?>
Expand All @@ -41,11 +43,16 @@ endif;
$headingTerm = $this->siteSetting('browse_heading_property_term');
$bodyTerm = $this->siteSetting('browse_body_property_term');
foreach ($items as $item):
$heading = $headingTerm ? $item->value($headingTerm, ['default' => $translate('[Untitled]'), 'lang' => ($filterLocale ? [$lang, ''] : null)]) : $item->displayTitle(null, ($filterLocale ? [$lang, ''] : null));
$body = $bodyTerm ? $item->value($bodyTerm, ['lang' => ($filterLocale ? [$lang, ''] : null)]) : $item->displayDescription(null, ($filterLocale ? [$lang, ''] : null));
$heading = $headingTerm ? $item->value($headingTerm, ['default' => $translate('[Untitled]'), 'lang' => $valueLang]) : $item->displayTitle(null, $valueLang);
$body = $bodyTerm ? $item->value($bodyTerm, ['lang' => $valueLang]) : $item->displayDescription(null, $valueLang);
?>
<li class="item resource">
<?php echo $item->linkPretty('medium', $heading); ?>
<?php
$linkContent = sprintf('%s<span class="resource-name">%s</span>',
$thumbnail($item, 'medium'),
$escape($heading));
echo $item->linkRaw($linkContent, null, ['class' => 'resource-link']);
?>
<?php if ($body): ?>
<div class="description"><?php echo $escape($body); ?></div>
<?php endif; ?>
Expand Down
3 changes: 2 additions & 1 deletion application/view/omeka/site/item/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ $this->headLink()->appendStylesheet($this->assetUrl('css/resource-page-blocks.cs
$this->htmlElement('body')->appendAttribute('class', 'item resource show');
$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;
?>
<?php echo $this->pageTitle($item->displayTitle(null, ($filterLocale ? $lang : null)), 2); ?>
<?php echo $this->pageTitle($item->displayTitle(null, $valueLang), 2); ?>
<h3><?php echo $translate('Item'); ?></h3>
<?php $this->trigger('view.show.before'); ?>
<?php echo $this->resourcePageBlocks($item)->getBlocks(); ?>
Expand Down
7 changes: 5 additions & 2 deletions application/view/omeka/site/media/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ $translate = $this->plugin('translate');
$item = $media->item();
$this->headLink()->appendStylesheet($this->assetUrl('css/resource-page-blocks.css', 'Omeka'));
$this->htmlElement('body')->appendAttribute('class', 'media resource show');
$filterLocale = (bool) $this->siteSetting('filter_locale_values');
$lang = $this->lang();
$valueLang = $filterLocale ? [$lang, ''] : null;
?>

<?php echo $this->pageTitle($media->displayTitle(), 2); ?>
<?php echo $this->pageTitle($media->displayTitle(null, $valueLang), 2); ?>
<h3><?php echo $translate('Media'); ?></h3>
<?php $this->trigger('view.show.before'); ?>
<p class="media-parent-item">
<?php echo sprintf($translate('Part of %s'), $item->link($item->displayTitle())); ?>
<?php echo sprintf($translate('Part of %s'), $item->link($item->displayTitle(null, $valueLang))); ?>
</p>
<?php echo $this->resourcePageBlocks($media)->getBlocks(); ?>
<?php $this->trigger('view.show.after'); ?>

0 comments on commit 4753f8e

Please sign in to comment.