Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view events that prepend to browse actions #2149

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion application/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,12 @@ public function deleteFulltextMedia(ZendEvent $event)
public function deleteFulltextPreSitePage(ZendEvent $event)
{
$request = $event->getParam('request');
$conditions = $request->getId();
if (!is_array($conditions)) {
$conditions = ['id' => $conditions];
}
$em = $this->getServiceLocator()->get('Omeka\EntityManager');
$sitePage = $em->getRepository('Omeka\Entity\SitePage')->findOneBy($request->getId());
$sitePage = $em->getRepository('Omeka\Entity\SitePage')->findOneBy($conditions);
$request->setOption('deleted_entity_id', $sitePage->getId());
}

Expand Down
12 changes: 10 additions & 2 deletions application/src/Api/Adapter/SitePageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,16 @@ private function hydrateBlocks(array $blockData, SitePage $page, ErrorStore $err
return;
}
if (!is_array($inputBlock['o:data'])) {
$errorStore->addError('o:block', 'Block data must not be a scalar value.'); // @translate
return;
// Attempt to convert the data to an array before returning with
// an error. This is needed in part so fallback blocks don't
// lose their data onced saved.
$blockData = json_decode($inputBlock['o:data'], true);
if (is_array($blockData)) {
$inputBlock['o:data'] = $blockData;
} else {
$errorStore->addError('o:block', 'Block data must not be a scalar value.'); // @translate
return;
}
}

$block->setLayout($inputBlock['o:layout']);
Expand Down
6 changes: 5 additions & 1 deletion application/src/Site/BlockLayout/Fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Omeka\Api\Representation\SitePageRepresentation;
use Omeka\Api\Representation\SitePageBlockRepresentation;
use Omeka\Stdlib\Message;
use Laminas\Form\Element;
use Laminas\View\Renderer\PhpRenderer;

class Fallback extends AbstractBlockLayout
Expand Down Expand Up @@ -34,7 +35,10 @@ public function getLabel()
public function form(PhpRenderer $view, SiteRepresentation $site,
SitePageRepresentation $page = null, SitePageBlockRepresentation $block = null
) {
return $view->translate('This layout is invalid.');
// Preserve the original data.
$element = new Element\Hidden("o:block[__blockIndex__][o:data]");
$element->setValue(json_encode($block->data()));
return $view->translate('This layout is invalid.') . $view->formElement($element);
}

public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/asset/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $this->headScript()->appendFile($this->assetUrl('js/asset-browse.js', 'Omeka'));
<span class="asset-name"><?php echo $escape($asset->name()); ?></span>
</span>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $asset]); ?>
<?php if ($asset->userIsAllowed('update')): ?>
<li><?php echo $asset->link('', 'edit', [
'class' => 'o-icon-edit',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/asset/edit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $deleteButton = $asset->userIsAllowed('delete')
<?php echo $this->formCollection($form, false); ?>

<div id="page-actions">
<?php $this->trigger('view.edit.page_actions', ['resource' => $asset]); ?>
<?php echo (isset($deleteButton)) ? $deleteButton : ''; ?>
<?php echo $this->cancelButton(); ?>
<button type="submit"><?php echo $escape('Save'); ?></button>
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/item-set/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ $this->htmlElement('body')->appendAttribute('class', 'item-sets browse');
<span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $itemSet]); ?>
<?php if ($itemSet->userIsAllowed('update')): ?>
<li><?php echo $itemSet->link('', 'edit', [
'class' => 'o-icon-edit',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/item-set/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $sectionNavs = [
<?php echo $this->pageTitle($itemSet->displayTitle(), 1, $translate('Item sets')); ?>

<div id="page-actions">
<?php $this->trigger('view.show.page_actions', ['resource' => $itemSet]); ?>
<?php if ($itemSet->userIsAllowed('update')): ?>
<?php echo $itemSet->link($translate('Edit item set'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/item/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ $this->htmlElement('body')->appendAttribute('class', 'items browse');
<span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $item]); ?>
<?php if ($item->userIsAllowed('update')): ?>
<li><?php echo $item->link('', 'edit', [
'class' => 'o-icon-edit',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/item/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $itemMedia = $item->media();
?>
<?php echo $this->pageTitle($item->displayTitle(), 1, $translate('Items')); ?>
<div id="page-actions">
<?php $this->trigger('view.show.page_actions', ['resource' => $item]); ?>
<?php if ($item->userIsAllowed('update')): ?>
<?php echo $item->link($translate('Edit item'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/media/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ $this->htmlElement('body')->appendAttribute('class', 'media browse');
<span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $media]); ?>
<?php if ($media->userIsAllowed('update')): ?>
<li><?php echo $media->link('', 'edit', [
'class' => 'o-icon-edit',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/media/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $sectionNavs = [
<?php echo $this->pageTitle($media->displayTitle(), 1, $translate('Media')); ?>

<div id="page-actions">
<?php $this->trigger('view.show.page_actions', ['resource' => $media]); ?>
<?php echo $media->link($translate('Edit media'), 'edit', ['class' => 'button']); ?>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $this->htmlElement('body')->appendAttribute('class', 'resource-templates browse'
<td>
<?php echo $resourceTemplate->link($resourceTemplate->label()); ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $resourceTemplate]); ?>
<?php if ($resourceTemplate->userIsAllowed('update')): ?>
<li><?php echo $resourceTemplate->link('', 'edit', [
'class' => 'o-icon-edit',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/resource-template/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $this->htmlElement('body')->appendAttribute('class', 'resource-templates show');
<?php echo $this->pageTitle($resourceTemplate->label(), 1, $translate('Resource templates')); ?>

<div id="page-actions">
<?php $this->trigger('view.show.page_actions', ['resource' => $resourceTemplate]); ?>
<a class="button" href="<?php echo $this->escapeHtml($this->url(null, ['action' => 'export'], true)); ?>"><?php echo $translate('Export'); ?></a>
<?php if ($resourceTemplate->userIsAllowed('update')): ?>
<a class="button" href="<?php echo $escape($resourceTemplate->url('edit')); ?>"><?php echo $translate('Edit resource template'); ?></a>
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/user/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ $userIsAllowedBatchDelete = $this->userIsAllowed('Omeka\Api\Adapter\UserAdapter'
<span class="o-icon-user-inactive" aria-label="<?php echo $translate('Inactive'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $user]); ?>
<?php if ($userIsAllowedUpdate): ?>
<li><?php echo $user->link('', 'edit', [
'class' => 'o-icon-edit',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/user/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $this->htmlElement('body')->appendAttribute('class', 'users show');
<?php echo $this->pageTitle($user->email(), 1, $translate('Users')); ?>

<div id="page-actions">
<?php $this->trigger('view.show.page_actions', ['resource' => $user]); ?>
<?php if ($user->userIsAllowed('update')): ?>
<a class="button" href="<?php echo $escape($user->url('edit')); ?>"><?php echo $translate('Edit user'); ?></a>
<?php endif; ?>
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/vocabulary/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $this->htmlElement('body')->appendAttribute('class', 'vocabs browse');
<td>
<?php echo $escape($translate($vocabulary->label())); ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $vocabulary]); ?>
<?php if (!$vocabulary->isPermanent()): ?>
<?php if ($vocabulary->userIsAllowed('update')): ?>
<li><?php echo $vocabulary->link('', 'edit', [
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/vocabulary/classes.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $this->htmlElement('body')->appendAttribute('class', 'browse vocabularies vocabu
<?php echo $escape($translate($resourceClass->label())); ?>
</span>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $resourceClass]); ?>
<li><?php echo $this->hyperlink('', '#', [
'data-sidebar-content-url' => $resourceClass->url('show-details'),
'class' => 'o-icon-more sidebar-content',
Expand Down
1 change: 1 addition & 0 deletions application/view/omeka/admin/vocabulary/edit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $form->prepare();
<?php $this->trigger('view.edit.before'); ?>
<?php echo $this->form()->openTag($form); ?>
<div id="page-actions">
<?php $this->trigger('view.edit.page_actions', ['resource' => $vocabulary]); ?>
<a href="#" class="delete button"><?php echo $translate('Delete'); ?></a>
<?php echo $this->cancelButton(); ?>
<button><?php echo $translate('Save'); ?></button>
Expand Down
11 changes: 6 additions & 5 deletions application/view/omeka/admin/vocabulary/properties.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ $this->htmlElement('body')->appendAttribute('class', 'browse vocabularies vocabu
<?php echo $escape($translate($property->label())); ?>
</span>
<ul class="actions">
<li><?php echo $this->hyperlink('', '#', [
'data-sidebar-content-url' => $property->url('show-details'),
'class' => 'o-icon-more sidebar-content',
'title' => $translate('Details'),
]); ?></li>
<?php $this->trigger('view.browse.actions', ['resource' => $property]); ?>
<li><?php echo $this->hyperlink('', '#', [
'data-sidebar-content-url' => $property->url('show-details'),
'class' => 'o-icon-more sidebar-content',
'title' => $translate('Details'),
]); ?></li>
</ul>
</td>
<td><?php echo $escape($translate($property->term())); ?></td>
Expand Down
3 changes: 2 additions & 1 deletion application/view/omeka/site-admin/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $this->htmlElement('body')->appendAttribute('class', 'sites browse');
<span class="o-icon-private" aria-label="<?php echo $translate('Private'); ?>"></span>
<?php endif; ?>
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $site]); ?>
<li><?php echo $this->hyperlink('', $site->siteUrl(), [
'target' => '_blank',
'class' => 'o-icon-external public',
Expand Down Expand Up @@ -65,7 +66,7 @@ $this->htmlElement('body')->appendAttribute('class', 'sites browse');
<?php echo $this->pagination(); ?>
</div>

<div class="sidebar">
<div id="sidebar" class="sidebar">
<?php echo $this->hyperlink('', '#', [
'class' => 'sidebar-close o-icon-close',
'title' => $translate('Close'),
Expand Down
3 changes: 3 additions & 0 deletions application/view/omeka/site-admin/index/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $this->htmlElement('body')->appendAttribute('class', 'sites show');
<?php echo $this->pageTitle($site->title(), 1, $translate('Sites')); ?>

<div id="page-actions">
<?php $this->trigger('view.show.page_actions', ['resource' => $site]); ?>
<?php if ($site->userIsAllowed('update')): ?>
<?php echo $site->link($translate('Edit'), null, ['class' => 'button']); ?>
<?php endif; ?>
Expand Down Expand Up @@ -47,3 +48,5 @@ $this->htmlElement('body')->appendAttribute('class', 'sites show');
</div>
<?php endif; ?>
</dl>

<?php $this->trigger('view.show.after'); ?>
1 change: 1 addition & 0 deletions application/view/omeka/site-admin/page/edit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $form->prepare();
<?php $this->trigger('view.edit.before'); ?>
<?php echo $this->form()->openTag($form); ?>
<div id="page-actions">
<?php $this->trigger('view.edit.page_actions', ['resource' => $page]); ?>
<?php if ($page->isPublic()): ?>
<?php echo $this->hyperlink('', '#', [
'class' => 'o-icon-public button',
Expand Down
3 changes: 2 additions & 1 deletion application/view/omeka/site-admin/page/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $this->htmlElement('body')->appendAttribute('class', 'sites pages browse');
<?php endif; ?>
<input type="hidden" name="o:page[][o:id]" value="<?php echo $escape($page->id()); ?>">
<ul class="actions">
<?php $this->trigger('view.browse.actions', ['resource' => $page]); ?>
<?php if ($page->userIsAllowed('read')): ?>
<li><?php echo $hyperlink('', $page->siteUrl(), [
'target' => '_blank',
Expand Down Expand Up @@ -72,7 +73,7 @@ $this->htmlElement('body')->appendAttribute('class', 'sites pages browse');
</tbody>
</table>

<div class="sidebar">
<div id="sidebar" class="sidebar">
<?php echo $hyperlink('', '#', [
'class' => 'sidebar-close o-icon-close',
'title' => $translate('Close'),
Expand Down
Loading