Skip to content

Commit

Permalink
Addes the item copying action to the item controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukuchi committed Jan 16, 2020
1 parent f1519de commit 4d633b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions application/src/Controller/Admin/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public function editAction()
return $this->getAddEditView();
}

public function copyAction()
{
return $this->getAddEditView();
}

/**
* Get the add/edit view.
*
Expand All @@ -214,7 +219,7 @@ protected function getAddEditView()
$form->setAttribute('enctype', 'multipart/form-data');
$form->setAttribute('id', '$action-item');

if ('edit' === $action) {
if ('edit' === $action || 'copy' === $action) {
$item = $this->api()->read('items', $this->params('id'))->getContent();
}

Expand Down Expand Up @@ -252,7 +257,7 @@ protected function getAddEditView()

$view = new ViewModel;
$view->setVariable('form', $form);
if ('edit' === $action) {
if ('edit' === $action || 'copy' === $action) {
$view->setVariable('item', $item);
$view->setVariable('resource', $item);
}
Expand Down
25 changes: 25 additions & 0 deletions application/view/omeka/admin/item/copy.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'add items');
?>

<script type='text/javascript'>
var valuesJson = <?php echo json_encode($item->values()); ?>;
</script>

<?php echo $this->pageTitle("Copied from " . $item->displayTitle(), 1, $translate('Items')); ?>
<?php $this->trigger('view.add.before'); ?>
<?php
echo $this->partial('omeka/admin/item/form.phtml', [
'form' => $form,
'item' => $item,
'resource' => $resource,
'mediaForms' => $mediaForms,
'submitLabel' => $translate('Add'),
'sectionNavEvent' => 'view.add.section_nav',
'action' => 'add',
]);
?>

<?php $this->trigger('view.add.after'); ?>

0 comments on commit 4d633b4

Please sign in to comment.