Skip to content

Commit

Permalink
Add toolbar action to copy article (sulu#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogamoore authored and wachterjohannes committed Dec 14, 2023
1 parent 878132e commit 95d9de3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
15 changes: 11 additions & 4 deletions Admin/ArticleAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,20 @@ 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
1 change: 0 additions & 1 deletion Document/Subscriber/ArticleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ public function handleUnpublish(UnpublishEvent $event): void
return;
}

/* @phpstan-ignore-next-line See https://github.com/phpstan/phpstan/issues/3779 */
$this->liveIndexer->remove($document, $event->getLocale());
$this->liveIndexer->flush();

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
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1 || ^6.2.0.1 || ^7.2.0.1",
"jms/serializer": "^3.3",
"jms/serializer-bundle": "^3.3 || ^4.0",
"sulu/sulu": "^2.3 || ^2.3@dev",
"sulu/sulu": "~2.4.13 || ^2.5.9@dev",
"symfony/config": "^4.3 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0",
"symfony/http-foundation": "^4.3 || ^5.0 || ^6.0",
Expand Down Expand Up @@ -125,6 +125,9 @@
]
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
}
}
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,11 @@ parameters:
count: 1
path: Document/Subscriber/ArticleSubscriber.php

-
message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Document\\\\Index\\\\IndexerInterface\\:\\:remove\\(\\) invoked with 1 parameter, 2 required\\.$#"
count: 2
path: Document/Subscriber/ArticleSubscriber.php

-
message: "#^Method Sulu\\\\Bundle\\\\ArticleBundle\\\\Document\\\\Subscriber\\\\ArticleSubscriber\\:\\:getChildren\\(\\) has parameter \\$node with no value type specified in iterable type PHPCR\\\\NodeInterface\\.$#"
count: 1
Expand Down

0 comments on commit 95d9de3

Please sign in to comment.