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 authored and alexander-schranz committed Feb 14, 2023
1 parent 02e90f6 commit f9fb2cc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
16 changes: 12 additions & 4 deletions Admin/ArticleAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +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'),
]
$editDropdownToolbarActions
);
}

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

// prepare vars
$view = null;
Expand Down
22 changes: 22 additions & 0 deletions Tests/Functional/Controller/ArticleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,28 @@ 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 f9fb2cc

Please sign in to comment.