forked from CollaboraOnline/collabora-drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from donquixote/group-integration-links
Add view field links.
- Loading branch information
Showing
10 changed files
with
751 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Implements hook_views_data_alter(). | ||
*/ | ||
function collabora_online_views_data_alter(array &$data): void { | ||
$data['media']['collabora_preview'] = [ | ||
'title' => t('Link to view in Collabora Online'), | ||
'group' => t('Media'), | ||
'field' => [ | ||
'id' => 'media_collabora_preview', | ||
], | ||
]; | ||
$data['media']['collabora_edit'] = [ | ||
'title' => t('Link to edit in Collabora Online'), | ||
'group' => t('Media'), | ||
'field' => [ | ||
'id' => 'media_collabora_edit', | ||
], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
modules/collabora_online_group/collabora_online_group.install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use Drupal\views\Entity\View; | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function collabora_online_group_install(bool $is_syncing): void { | ||
if ( | ||
$is_syncing || | ||
!\Drupal::moduleHandler()->moduleExists('views') || | ||
!($view = View::load('group_media')) | ||
) { | ||
return; | ||
} | ||
|
||
// Load display and apply changes. | ||
$display = &$view->getDisplay('default'); | ||
if ($display === NULL) { | ||
return; | ||
} | ||
|
||
// Add new fields to the display. | ||
$display['display_options']['fields'] += [ | ||
'collabora_preview' => [ | ||
'id' => 'collabora_preview', | ||
'table' => 'media', | ||
'field' => 'collabora_preview', | ||
'plugin_id' => 'media_collabora_preview', | ||
'label' => '', | ||
'exclude' => TRUE, | ||
'text' => t('View in Collabora Online'), | ||
], | ||
]; | ||
$display['display_options']['fields'] += [ | ||
'collabora_edit' => [ | ||
'id' => 'collabora_edit', | ||
'table' => 'media', | ||
'field' => 'collabora_edit', | ||
'plugin_id' => 'media_collabora_edit', | ||
'label' => '', | ||
'exclude' => TRUE, | ||
'text' => t('Edit in Collabora Online'), | ||
], | ||
]; | ||
// Add new fields as options for the dropbutton and move the element to the end. | ||
$dropbutton = $display['display_options']['fields']['dropbutton']; | ||
$dropbutton['fields'] += [ | ||
'collabora_preview' => 'collabora_preview', | ||
'collabora_edit' => 'collabora_edit', | ||
]; | ||
unset($display['display_options']['fields']['dropbutton']); | ||
$display['display_options']['fields']['dropbutton'] = $dropbutton; | ||
|
||
$view->save(); | ||
} |
146 changes: 146 additions & 0 deletions
146
modules/collabora_online_group/tests/src/Functional/GroupMediaViewsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\collabora_online_group\Functional; | ||
|
||
use Drupal\Core\Url; | ||
use Drupal\group\PermissionScopeInterface; | ||
use Drupal\media\Entity\Media; | ||
use Drupal\Tests\BrowserTestBase; | ||
use Drupal\Tests\collabora_online\Traits\MediaCreationTrait; | ||
use Drupal\Tests\collabora_online_group\Traits\GroupRelationTrait; | ||
use Drupal\Tests\group\Traits\GroupTestTrait; | ||
use Drupal\Tests\media\Traits\MediaTypeCreationTrait; | ||
use Drupal\user\RoleInterface; | ||
|
||
/** | ||
* Test the modifications performend in groupmedia view by the module. | ||
*/ | ||
class GroupMediaViewsTest extends BrowserTestBase { | ||
|
||
use MediaCreationTrait; | ||
use GroupRelationTrait; | ||
use GroupTestTrait; | ||
use MediaTypeCreationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'collabora_online_group', | ||
'views', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $defaultTheme = 'stark'; | ||
|
||
/** | ||
* Test the links for Collabora operations in the view. | ||
*/ | ||
public function testViewLinks(): void { | ||
// Add configuration needed for testing. | ||
$group_type = $this->createGroupType(['id' => 'group_type_1']); | ||
$this->createMediaType('file', [ | ||
'id' => 'document', | ||
'label' => 'Document', | ||
]); | ||
$this->createGroupRole([ | ||
'group_type' => 'group_type_1', | ||
'scope' => PermissionScopeInterface::INSIDER_ID, | ||
'global_role' => RoleInterface::AUTHENTICATED_ID, | ||
'permissions' => [ | ||
'view group', | ||
'access group_media overview', | ||
'view group_media:document entity', | ||
'edit any group_media:document in collabora', | ||
'preview group_media:document in collabora', | ||
], | ||
]); | ||
$this->createPluginRelation($group_type, 'group_media:document', [ | ||
'group_cardinality' => 0, | ||
'entity_cardinality' => 1, | ||
'use_creation_wizard' => FALSE, | ||
]); | ||
|
||
// Create content. | ||
$group = $this->createGroup(['type' => 'group_type_1']); | ||
for ($i = 0; $i < 3; $i++) { | ||
$media = $this->createMediaEntity('document', [ | ||
'id' => 'media_' . $i, | ||
'name' => 'Media ' . $i, | ||
]); | ||
$group->addRelationship($media, 'group_media:document'); | ||
} | ||
$user = $this->createUser([ | ||
'view the administration theme', | ||
'access administration pages', | ||
'access group overview', | ||
]); | ||
$group->addMember($user); | ||
|
||
// Go to the page and check the links added to the view. | ||
$this->drupalLogin($user); | ||
$this->drupalGet("group/{$group->id()}/media"); | ||
$assert_session = $this->assertSession(); | ||
|
||
// Check table header. | ||
$table = $assert_session->elementExists('css', 'table'); | ||
$table_header = $assert_session->elementExists('css', 'thead', $table); | ||
$rows = $table_header->findAll('css', 'tr'); | ||
$cols = $rows[0]->findAll('css', 'th'); | ||
$this->assertEquals('Media name', $cols[0]->getText()); | ||
$this->assertEquals('Bundle', $cols[1]->getText()); | ||
$this->assertEquals('Status', $cols[2]->getText()); | ||
$this->assertEquals('Publisher', $cols[3]->getText()); | ||
// Support different versions of groupmedia. | ||
$this->assertTrue(in_array($cols[4]->getText(), ['Operations', 'Dropbutton'])); | ||
|
||
// Check that rows contain new links for operations in Collabora. | ||
$table_body = $assert_session->elementExists('css', 'tbody', $table); | ||
$rows = $table_body->findAll('css', 'tr'); | ||
$i = 0; | ||
foreach (Media::loadMultiple() as $media) { | ||
$cols = $rows[$i]->findAll('css', 'td'); | ||
$this->assertEquals('Media ' . $i, $cols[0]->getText()); | ||
$this->assertEquals('Document', $cols[1]->getText()); | ||
$this->assertEquals('Yes', $cols[2]->getText()); | ||
$this->assertEquals('Anonymous', $cols[3]->getText()); | ||
$operation_links = $cols[4]->findAll('css', 'a'); | ||
$this->assertEquals('View in Collabora Online', $operation_links[0]->getText()); | ||
$this->assertEquals( | ||
Url::fromRoute( | ||
'collabora-online.view', | ||
[ | ||
'media' => $media->id() | ||
], | ||
[ | ||
'query' => [ | ||
'destination' => "/group/{$group->id()}/media", | ||
] | ||
] | ||
)->toString(), | ||
$operation_links[0]->getAttribute('href') | ||
); | ||
$this->assertEquals('Edit in Collabora Online', $operation_links[1]->getText()); | ||
$this->assertEquals( | ||
Url::fromRoute( | ||
'collabora-online.edit', | ||
[ | ||
'media' => $media->id() | ||
], | ||
[ | ||
'query' => [ | ||
'destination' => "/group/{$group->id()}/media", | ||
] | ||
] | ||
)->toString(), | ||
$operation_links[1]->getAttribute('href') | ||
); | ||
$i++; | ||
} | ||
} | ||
|
||
} |
36 changes: 0 additions & 36 deletions
36
modules/collabora_online_group/tests/src/Functional/SmokeTest.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\collabora_online\Plugin\views\field; | ||
|
||
use Drupal\collabora_online\Cool\CoolUtils; | ||
use Drupal\Core\StringTranslation\TranslatableMarkup; | ||
use Drupal\Core\Url; | ||
use Drupal\views\Attribute\ViewsField; | ||
use Drupal\views\Plugin\views\field\LinkBase; | ||
use Drupal\views\ResultRow; | ||
|
||
/** | ||
* Field handler for link to edit a collabora file. | ||
* | ||
* @ingroup views_field_handlers | ||
*/ | ||
#[ViewsField('media_collabora_edit')] | ||
class CollaboraEdit extends LinkBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUrlInfo(ResultRow $row): Url|null { | ||
/** @var \Drupal\media\MediaInterface $entity */ | ||
$entity = $this->getEntity($row); | ||
|
||
if ($entity === NULL) { | ||
return NULL; | ||
} | ||
|
||
return CoolUtils::getEditorUrl($entity, TRUE); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getDefaultLabel(): TranslatableMarkup { | ||
return $this->t('Edit in Collabora Online'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\collabora_online\Plugin\views\field; | ||
|
||
use Drupal\collabora_online\Cool\CoolUtils; | ||
use Drupal\Core\StringTranslation\TranslatableMarkup; | ||
use Drupal\Core\Url; | ||
use Drupal\views\Attribute\ViewsField; | ||
use Drupal\views\Plugin\views\field\LinkBase; | ||
use Drupal\views\ResultRow; | ||
|
||
/** | ||
* Field handler for link to preview a collabora file. | ||
* | ||
* @ingroup views_field_handlers | ||
*/ | ||
#[ViewsField('media_collabora_preview')] | ||
class CollaboraPreview extends LinkBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getUrlInfo(ResultRow $row): Url|null { | ||
/** @var \Drupal\media\MediaInterface $entity */ | ||
$entity = $this->getEntity($row); | ||
|
||
if ($entity === NULL) { | ||
return NULL; | ||
} | ||
|
||
return CoolUtils::getEditorUrl($entity, FALSE); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getDefaultLabel(): TranslatableMarkup { | ||
return $this->t('View in Collabora Online'); | ||
} | ||
} |
Oops, something went wrong.