Skip to content

Commit

Permalink
feat: add toolbar action to copy article
Browse files Browse the repository at this point in the history
  • Loading branch information
rogamoore committed Dec 28, 2022
1 parent c375e46 commit 695f139
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
17 changes: 12 additions & 5 deletions Admin/ArticleAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,21 @@ function(Localization $localization) {

if ($this->securityChecker->hasPermission(static::SECURITY_CONTEXT, PermissionTypes::LIVE)
&& $this->securityChecker->hasPermission(static::getArticleSecurityContext($typeKey), PermissionTypes::LIVE)) {

$editDropdownToolbarActions = [
new ToolbarAction('sulu_admin.delete_draft'),
new ToolbarAction('sulu_admin.set_unpublished'),
new ToolbarAction('sulu_admin.copy'),
];

if (\count($locales) > 1) {
$editDropdownToolbarActions[] = new ToolbarAction('sulu_admin.copy_locale');
}

$formToolbarActionsWithType[] = new DropdownToolbarAction(
'sulu_admin.edit',
'su-pen',
[
new ToolbarAction('sulu_admin.delete_draft'),
new ToolbarAction('sulu_admin.set_unpublished'),
new ToolbarAction('sulu_admin.copy')
]
$editDropdownToolbarActions
);
}

Expand Down
4 changes: 1 addition & 3 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,7 @@ public function postTriggerAction(string $id, Request $request): Response
{
// extract parameter
$action = $this->getRequestParameter($request, 'action', true);

# TODO: remove default - just for testing
$locale = $this->getRequestParameter($request, 'locale', true, 'de');
$locale = $this->getRequestParameter($request, 'locale', false);

// prepare vars
$view = null;
Expand Down
23 changes: 23 additions & 0 deletions Tests/Functional/Controller/ArticleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,29 @@ public function testCDelete()
$this->assertNull($this->findViewDocument($article2['id'], 'de'));
}

public function testCopy()
{
// create article
$sourceArticle = $this->testPost('Sulu ist toll - Artikel 1');
$this->publish($sourceArticle['id']);
$this->flush();

// trigger copy action
$this->client->jsonRequest('POST',
\sprintf('/api/articles/%s?action=copy', $sourceArticle['id'])
);
$response = $this->client->getResponse();

$result = \json_decode($response->getContent(), true);
$this->assertHttpStatusCode(200, $response);

$this->assertNotEquals($sourceArticle['id'], $result['id']);
$this->assertEquals($sourceArticle['title'], $result['title']);
$this->assertEquals($sourceArticle['articleType'], $result['articleType']);
$this->assertEquals(false, $result['publishedState']);
}


public function testCopyLocaleWithoutSource()
{
// prepare vars
Expand Down

0 comments on commit 695f139

Please sign in to comment.