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

Adding 'copy' action to the resource template browser. #1501

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion application/asset/css/iconfonts.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions application/asset/sass/iconfonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@
@extend .fa-external-link-alt;
}

.o-icon-copy {
@extend .fa-copy;
}

.screen-reader-text {
position: absolute;
top: -9999px;
Expand Down
14 changes: 12 additions & 2 deletions application/src/Controller/Admin/ResourceTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ public function editAction()
return $this->getAddEditView();
}

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

/**
* Get the add/edit view.
*
Expand All @@ -379,7 +384,7 @@ protected function getAddEditView()
$action = $this->params('action');
$form = $this->getForm(ResourceTemplateForm::class);

if ('edit' == $action) {
if ('edit' === $action || 'copy' === $action) {
$resourceTemplate = $this->api()
->read('resource_templates', $this->params('id'))
->getContent();
Expand All @@ -393,6 +398,9 @@ protected function getAddEditView()
if ($data['o:description_property']) {
$data['o:description_property[o:id]'] = $data['o:description_property']->id();
}
if ('copy' === $action) {
$data['o:label'] = 'Copy of ' . $data['o:label'];
}
$form->setData($data);
}

Expand Down Expand Up @@ -428,6 +436,8 @@ protected function getAddEditView()
$view = new ViewModel;
if ('edit' === $action) {
$view->setVariable('resourceTemplate', $resourceTemplate);
} elseif ('copy' === $action) {
$view->setVariable('label', $data['o:label']);
}
$view->setVariable('propertyRows', $this->getPropertyRows());
$view->setVariable('form', $form);
Expand Down Expand Up @@ -461,7 +471,7 @@ protected function getPropertyRows()
} else {
// Set default property rows
$propertyRows = [];
if ('edit' == $action) {
if ('edit' === $action || 'copy' === $action) {
$resourceTemplate = $this->api()
->read('resource_templates', $this->params('id'))
->getContent();
Expand Down
4 changes: 4 additions & 0 deletions application/view/omeka/admin/resource-template/browse.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ $sortHeadings = [
'class' => 'o-icon-edit',
'title' => $translate('Edit'),
]); ?></li>
<li><?php echo $resourceTemplate->link('', 'copy', [
'class' => 'o-icon-copy',
'title' => $translate('Copy'),
]); ?></li>
<?php endif; ?>
<?php if ($resourceTemplate->userIsAllowed('delete')): ?>
<li><?php echo $this->hyperlink('', '#', [
Expand Down
20 changes: 20 additions & 0 deletions application/view/omeka/admin/resource-template/copy.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
$translate = $this->plugin('translate');
?>
<?php $this->htmlElement('body')->appendAttribute('class', 'add resource-templates'); ?>

<?php echo $this->pageTitle($label, 1, $translate('Resource templates')); ?>

<?php
echo $this->partial(
'omeka/admin/resource-template/form.phtml',
[
'form' => $form,
'propertyRows' => $propertyRows,
'submitLabel' => $translate('Add'),
'action' => 'add',
]
);
?>

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