Skip to content

Commit 6ba234d

Browse files
committed
Swap the two parameters of getWopiClientURL().
1 parent a2afec1 commit 6ba234d

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

collabora_online.module

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function collabora_online_entity_operation(EntityInterface $entity): array {
123123
$discovery_fetcher = \Drupal::service(DiscoveryFetcherInterface::class);
124124
try {
125125
$discovery = $discovery_fetcher->getDiscovery();
126-
$wopi_client_edit_url = $discovery->getWopiClientURL($type, 'edit');
126+
$wopi_client_edit_url = $discovery->getWopiClientURL('edit', $type);
127127
if ($wopi_client_edit_url !== NULL) {
128128
$entries['collabora_online_edit'] = [
129129
'title' => t("Edit in Collabora Online"),

src/Controller/ViewerController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public function editor(MediaInterface $media, Request $request, $edit = FALSE):
7171
// @todo Get client url for the correct MIME type.
7272
$discovery = $this->discoveryFetcher->getDiscovery();
7373
$wopi_client_url = $edit
74-
? $discovery->getWopiClientURL(action: 'edit')
75-
: ($discovery->getWopiClientURL(action: 'view')
74+
? $discovery->getWopiClientURL('edit')
75+
: ($discovery->getWopiClientURL('view')
7676
// With the typical discovery.xml from Collabora, some MIME types that
7777
// are viewable have an 'edit' or 'view_comment' action but no 'view'
7878
// action.
79-
?? $discovery->getWopiClientURL(action: 'edit')
80-
?? $discovery->getWopiClientURL(action: 'view_comment'));
79+
?? $discovery->getWopiClientURL('edit')
80+
?? $discovery->getWopiClientURL('view_comment'));
8181
}
8282
catch (CollaboraNotAvailableException $e) {
8383
$this->logger->warning(

src/Discovery/Discovery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function getWopiClientURL(string $mimetype = 'text/plain', string $action = 'view'): ?string {
35+
public function getWopiClientURL(string $action = 'view', string $mimetype = 'text/plain'): ?string {
3636
$result = $this->parsedXml->xpath(sprintf(
3737
"/wopi-discovery/net-zone/app[@name='%s']/action[@name='%s']",
3838
$mimetype,

src/Discovery/DiscoveryInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ interface DiscoveryInterface {
2222
/**
2323
* Gets the URL for the WOPI client.
2424
*
25-
* @param string $mimetype
26-
* Mime type for which to get the WOPI client URL.
27-
* This refers to config entries in the discovery.xml file.
2825
* @param string $action
2926
* Name of the action/operation for which to get the url.
3027
* Typical values are 'view', 'edit' or 'view_comment'.
28+
* @param string $mimetype
29+
* Mime type for which to get the WOPI client URL.
30+
* This refers to config entries in the discovery.xml file.
3131
*
3232
* @return string|null
3333
* The WOPI client URL, or NULL if none provided for the MIME type and
3434
* operation.
3535
*/
36-
public function getWopiClientURL(string $mimetype = 'text/plain', string $action = 'view'): ?string;
36+
public function getWopiClientURL(string $action = 'view', string $mimetype = 'text/plain'): ?string;
3737

3838
/**
3939
* Gets the public key used for proofing.

tests/src/Unit/CollaboraDiscoveryTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ public function testWopiClientUrl(): void {
2929
);
3030
$this->assertSame(
3131
'http://spreadsheet.collabora.test:9980/browser/61cf2b4/cool.html?',
32-
$discovery->getWopiClientURL('text/spreadsheet', 'edit'),
32+
$discovery->getWopiClientURL('edit', 'text/spreadsheet'),
3333
);
3434
// Test unknown mime type.
35-
$this->assertNull($discovery->getWopiClientURL('text/unknown', 'view'));
35+
$this->assertNull($discovery->getWopiClientURL('view', 'text/unknown'));
3636
$this->assertSame(
3737
'http://csv.collabora.test:9980/browser/61cf2b4/cool.html?',
38-
$discovery->getWopiClientURL('text/csv', 'edit'),
38+
$discovery->getWopiClientURL('edit', 'text/csv'),
3939
);
4040
$this->assertSame(
4141
'http://view.csv.collabora.test:9980/browser/61cf2b4/cool.html?',
42-
$discovery->getWopiClientURL('text/csv', 'view'),
42+
$discovery->getWopiClientURL('view', 'text/csv'),
4343
);
4444
// Test the default MIME type 'text/plain' which has only 'edit' action in
4545
// the example file, but no 'view' action.
46-
$this->assertNull($discovery->getWopiClientURL(action: 'edit'));
47-
$this->assertNotNull($discovery->getWopiClientURL(action: 'view'));
46+
$this->assertNull($discovery->getWopiClientURL('edit'));
47+
$this->assertNotNull($discovery->getWopiClientURL('view'));
4848
// Test a MIME type with no action name specified.
4949
// This does not occur in the known discovery.xml, but we still want a
5050
// well-defined behavior in that case.
51-
$this->assertNull($discovery->getWopiClientURL('image/png', 'edit'));
52-
$this->assertNull($discovery->getWopiClientURL('image/png', 'view'));
51+
$this->assertNull($discovery->getWopiClientURL('edit', 'image/png'));
52+
$this->assertNull($discovery->getWopiClientURL('view', 'image/png'));
5353
}
5454

5555
/**
@@ -72,7 +72,7 @@ public function testRealisticDiscoveryXml(): void {
7272
foreach ($mimetypes as $mimetype) {
7373
$type_supported_actions = [];
7474
foreach (['edit', 'view_comment', 'view'] as $action) {
75-
$url = $discovery->getWopiClientURL($mimetype, $action);
75+
$url = $discovery->getWopiClientURL($action, $mimetype);
7676
if ($url !== NULL) {
7777
$this->assertSame($known_url, $url);
7878
$type_supported_actions[] = $action;

0 commit comments

Comments
 (0)